VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/seaborn-style-and-color/

⇱ Seaborn | Style And Color - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Seaborn | Style And Color

Last Updated : 29 Jan, 2021

Seaborn is a statistical plotting library in python. It has beautiful default styles. This article deals with the ways of styling the different kinds of plots in seaborn. 

Seaborn Figure Styles


This affects things like the color of the axes, whether a grid is enabled by default, and other aesthetic elements.

The ways of styling themes are as follows:

  • white
  • dark
  • whitegrid
  • darkgrid
  • ticks


Set the background to be white:

Given style with the help of countplot and the dataset is present in seaborn by default. load_dataset() function is used to load the dataset. set_style() function is used for plot styling.

Output: 
 

👁 Image


 

Set the background to ticks:

Ticks appear on the sides of the plot on setting it as set_style('ticks'). palette attribute is used to set the color of the bars. It helps to distinguish between chunks of data.

Output:

👁 Image

Set the background to be darkgrid:

Darkgrid appear on the sides of the plot on setting it as set_style('darkgrid'). palette attribute is used to set the color of the bars. It helps to distinguish between chunks of data.

Output:

👁 Image

Set the background to be Whitegrid:

Whitegrid appears on the sides of the plot on setting it as set_style('whitegrid'). palette attribute is used to set the color of the bars. It helps to distinguish between chunks of data.

Output:

👁 Image

Removing Axes Spines

The despine() is a function that removes the spines from the right and upper portion of the plot by default. sns.despine(left = True) helps remove the spine from the left.
 

Output 
 

👁 Image

Size and aspect

Non grid plot: The figure() is a matplotlib function used to plot the figures. The figsize is used to set the size of the figure. 
 

Output: 
 

👁 Image

Grid type plot: This example shows a regression plot of tips vs the total_bill from the dataset. lmplot stands for linear model plot and is used to create a regression plot. x ='total_bill' sets the x axis to total_bill. y='tip' sets the y axis to tips. size=2 is used to the size(the height)of the plot. aspect is used to set the width keeping the width constant.
 

Output: 
 

👁 Image

Scale and Context

The set_context() allows us to override default parameters. This affects things like the size of the labels, lines, and other elements of the plot, but not the overall style. 

The context are:

  • poster
  • paper
  • notebook
  • talk

Example 1: using poster.

Output:
 

👁 Image

Example 2: Using paper.

Output:

👁 Image

Example 3: Using notebook.

Output:

👁 Image

Example 4: Using talk.

Output:

👁 Image


 

Comment
Article Tags: