Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Plots Decoration | Plotting with Seaborn
Ultimate Visualization with Python

Swipe to show menu

book
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:

12345678910
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()
copy

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.

Note
Study More

You can explore more about different palletes in "Choosing color palettes" article.

1234567891011121314
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()
copy

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.

1234567891011121314151617
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()
copy
Note
Study More

You can explore more in set_context() documentation.

Task

Swipe to start coding

  1. Use the correct function to set the style to 'dark'.
  2. Use the correct function to set the palette to 'rocket'.
  3. Use the correct function to set the context to 'talk'.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 3

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

book
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:

12345678910
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()
copy

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.

Note
Study More

You can explore more about different palletes in "Choosing color palettes" article.

1234567891011121314
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()
copy

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.

1234567891011121314151617
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()
copy
Note
Study More

You can explore more in set_context() documentation.

Task

Swipe to start coding

  1. Use the correct function to set the style to 'dark'.
  2. Use the correct function to set the palette to 'rocket'.
  3. Use the correct function to set the context to 'talk'.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 3
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt