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

Contenido del Curso

Ultimate Visualization with Python

Ultimate Visualization with Python

1. Matplotlib Introduction
2. Creating Commonly Used Plots
3. Plots Customization
4. More Statistical Plots
5. Plotting with Seaborn

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

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

12345678910
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).

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:

123456789101112
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

You can explore more about set_context() in its documentation.

Tarea

  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'.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3
toggle bottom row

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

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

12345678910
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).

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:

123456789101112
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

You can explore more about set_context() in its documentation.

Tarea

  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'.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3
toggle bottom row

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

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

12345678910
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).

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:

123456789101112
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

You can explore more about set_context() in its documentation.

Tarea

  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'.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

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:

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

12345678910
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).

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:

123456789101112
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

You can explore more about set_context() in its documentation.

Tarea

  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'.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 5. Capítulo 3
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt