Plots Decoration
Setting Style
seaborn
provides the set_style()
function specifically for setting the visual style of your plots. This function requires a single mandatory parameter called style
. The style
parameter accepts several predefined options, each representing a distinct style:
'white'
'dark'
'whitegrid'
'darkgrid'
'ticks'
Feel free to experiment with them:
12345678910import 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 is to change the colors of plot elements in seaborn
using the set_palette()
function, focusing on its only required parameter: palette
:
- 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 about different palletes in "Choosing color palettes" article.
1234567891011121314import 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).
The most important parameter is context
, which can be either a dict
of parameters or a string
representing the name of a preconfigured set.
The default context
is 'notebook'
. Other available contexts include 'paper'
, 'talk'
, and 'poster'
, which are essentially scaled versions of the notebook
parameters.
1234567891011121314151617import 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 in set_context()
documentation.
Swipe to start coding
- 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'
.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.85Awesome!
Completion rate improved to 3.85
Plots Decoration
Setting Style
seaborn
provides the set_style()
function specifically for setting the visual style of your plots. This function requires a single mandatory parameter called style
. The style
parameter accepts several predefined options, each representing a distinct style:
'white'
'dark'
'whitegrid'
'darkgrid'
'ticks'
Feel free to experiment with them:
12345678910import 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 is to change the colors of plot elements in seaborn
using the set_palette()
function, focusing on its only required parameter: palette
:
- 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 about different palletes in "Choosing color palettes" article.
1234567891011121314import 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).
The most important parameter is context
, which can be either a dict
of parameters or a string
representing the name of a preconfigured set.
The default context
is 'notebook'
. Other available contexts include 'paper'
, 'talk'
, and 'poster'
, which are essentially scaled versions of the notebook
parameters.
1234567891011121314151617import 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 in set_context()
documentation.
Swipe to start coding
- 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'
.
Solution
Thanks for your feedback!
single
Awesome!
Completion rate improved to 3.85
Plots Decoration
Swipe to show menu
Setting Style
seaborn
provides the set_style()
function specifically for setting the visual style of your plots. This function requires a single mandatory parameter called style
. The style
parameter accepts several predefined options, each representing a distinct style:
'white'
'dark'
'whitegrid'
'darkgrid'
'ticks'
Feel free to experiment with them:
12345678910import 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 is to change the colors of plot elements in seaborn
using the set_palette()
function, focusing on its only required parameter: palette
:
- 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 about different palletes in "Choosing color palettes" article.
1234567891011121314import 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).
The most important parameter is context
, which can be either a dict
of parameters or a string
representing the name of a preconfigured set.
The default context
is 'notebook'
. Other available contexts include 'paper'
, 'talk'
, and 'poster'
, which are essentially scaled versions of the notebook
parameters.
1234567891011121314151617import 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 in set_context()
documentation.
Swipe to start coding
- 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'
.
Solution
Thanks for your feedback!