Зміст курсу
Ultimate Visualization with Python
Ultimate Visualization with Python
Plots Decoration
Setting Style
First, let’s start with setting the style for the plot. seaborn
has a set_style()
function exactly for this purpose. We are interested in its only required parameter called style
. It has several possible values, which are all different styles:
'white'
;'dark'
;'whitegrid'
;'darkgrid'
;'ticks'
.
Feel free to experiment with them:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Palette
Another option you have is to change the colors of the plot elements in seaborn
using the set_palette()
function. We'll focus on its only required parameter palette
. Here are a few possible palettes:
- Circular palettes:
'hls'
,'husl'
; - Perceptually uniform palettes:
'rocket'
,'magma'
,'mako'
, etc; - Diverging color palettes:
'RdBu'
,'PRGn'
, etc; - Sequential color palettes:
'Greys'
,'Blues'
, etc.
You can explore more of them here. Once again, feel free to experiment with different palettes:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Context
There is another function in the seaborn
library, set_context()
. It affects such aspects as the size of the labels, lines, and other elements of the plot (the overall style is not affected).
Its most important parameter context
which can either be a dictionary (dict
) of parameters or a name of a preconfigured set (string
type).
'notebook'
is the default context
, other contexts are 'paper'
, 'talk'
, and 'poster'
, which are essentially just versions of the notebook
parameters scaled by a certain value.
Here is an example, you can try different contexts and see the difference:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Setting the context sns.set_context('paper') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
You can explore more about set_context()
in its documentation.
Завдання
- Use the correct function to set the style to
'dark'
. - Use the correct function to set the palette to
'rocket'
. - Use the correct function to set the context to
'talk'
.
Дякуємо за ваш відгук!
Plots Decoration
Setting Style
First, let’s start with setting the style for the plot. seaborn
has a set_style()
function exactly for this purpose. We are interested in its only required parameter called style
. It has several possible values, which are all different styles:
'white'
;'dark'
;'whitegrid'
;'darkgrid'
;'ticks'
.
Feel free to experiment with them:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Palette
Another option you have is to change the colors of the plot elements in seaborn
using the set_palette()
function. We'll focus on its only required parameter palette
. Here are a few possible palettes:
- Circular palettes:
'hls'
,'husl'
; - Perceptually uniform palettes:
'rocket'
,'magma'
,'mako'
, etc; - Diverging color palettes:
'RdBu'
,'PRGn'
, etc; - Sequential color palettes:
'Greys'
,'Blues'
, etc.
You can explore more of them here. Once again, feel free to experiment with different palettes:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Context
There is another function in the seaborn
library, set_context()
. It affects such aspects as the size of the labels, lines, and other elements of the plot (the overall style is not affected).
Its most important parameter context
which can either be a dictionary (dict
) of parameters or a name of a preconfigured set (string
type).
'notebook'
is the default context
, other contexts are 'paper'
, 'talk'
, and 'poster'
, which are essentially just versions of the notebook
parameters scaled by a certain value.
Here is an example, you can try different contexts and see the difference:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Setting the context sns.set_context('paper') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
You can explore more about set_context()
in its documentation.
Завдання
- Use the correct function to set the style to
'dark'
. - Use the correct function to set the palette to
'rocket'
. - Use the correct function to set the context to
'talk'
.
Дякуємо за ваш відгук!
Plots Decoration
Setting Style
First, let’s start with setting the style for the plot. seaborn
has a set_style()
function exactly for this purpose. We are interested in its only required parameter called style
. It has several possible values, which are all different styles:
'white'
;'dark'
;'whitegrid'
;'darkgrid'
;'ticks'
.
Feel free to experiment with them:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Palette
Another option you have is to change the colors of the plot elements in seaborn
using the set_palette()
function. We'll focus on its only required parameter palette
. Here are a few possible palettes:
- Circular palettes:
'hls'
,'husl'
; - Perceptually uniform palettes:
'rocket'
,'magma'
,'mako'
, etc; - Diverging color palettes:
'RdBu'
,'PRGn'
, etc; - Sequential color palettes:
'Greys'
,'Blues'
, etc.
You can explore more of them here. Once again, feel free to experiment with different palettes:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Context
There is another function in the seaborn
library, set_context()
. It affects such aspects as the size of the labels, lines, and other elements of the plot (the overall style is not affected).
Its most important parameter context
which can either be a dictionary (dict
) of parameters or a name of a preconfigured set (string
type).
'notebook'
is the default context
, other contexts are 'paper'
, 'talk'
, and 'poster'
, which are essentially just versions of the notebook
parameters scaled by a certain value.
Here is an example, you can try different contexts and see the difference:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Setting the context sns.set_context('paper') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
You can explore more about set_context()
in its documentation.
Завдання
- Use the correct function to set the style to
'dark'
. - Use the correct function to set the palette to
'rocket'
. - Use the correct function to set the context to
'talk'
.
Дякуємо за ваш відгук!
Setting Style
First, let’s start with setting the style for the plot. seaborn
has a set_style()
function exactly for this purpose. We are interested in its only required parameter called style
. It has several possible values, which are all different styles:
'white'
;'dark'
;'whitegrid'
;'darkgrid'
;'ticks'
.
Feel free to experiment with them:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Palette
Another option you have is to change the colors of the plot elements in seaborn
using the set_palette()
function. We'll focus on its only required parameter palette
. Here are a few possible palettes:
- Circular palettes:
'hls'
,'husl'
; - Perceptually uniform palettes:
'rocket'
,'magma'
,'mako'
, etc; - Diverging color palettes:
'RdBu'
,'PRGn'
, etc; - Sequential color palettes:
'Greys'
,'Blues'
, etc.
You can explore more of them here. Once again, feel free to experiment with different palettes:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
Setting Context
There is another function in the seaborn
library, set_context()
. It affects such aspects as the size of the labels, lines, and other elements of the plot (the overall style is not affected).
Its most important parameter context
which can either be a dictionary (dict
) of parameters or a name of a preconfigured set (string
type).
'notebook'
is the default context
, other contexts are 'paper'
, 'talk'
, and 'poster'
, which are essentially just versions of the notebook
parameters scaled by a certain value.
Here is an example, you can try different contexts and see the difference:
import seaborn as sns import matplotlib.pyplot as plt # Setting the style sns.set_style('darkgrid') # Setting the palette sns.set_palette('magma') # Setting the context sns.set_context('paper') # Loading a built-in dataset of the Titanic passengers titanic_df = sns.load_dataset('titanic') sns.countplot(data=titanic_df, x='class') plt.show()
You can explore more about set_context()
in its documentation.
Завдання
- Use the correct function to set the style to
'dark'
. - Use the correct function to set the palette to
'rocket'
. - Use the correct function to set the context to
'talk'
.