Skip to content
Related Articles

Related Articles

Seaborn – Coloring Boxplots with Palettes
  • Difficulty Level : Expert
  • Last Updated : 12 Nov, 2020

Adding the right set of color with your data visualization makes it more impressive and readable, seaborn color palettes make it easy to use colors with your visualization. In this article, we will see how to color boxplot with seaborn color palettes also learn the uses of seaborn color palettes and it can be applied to other plots as well. 

Step-by-step Approach:

Step 1: Load the python packages and libraries required to color a boxplot.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import libraries
import seaborn as sns  
import matplotlib.pyplot as plt

chevron_right




Step 2: Load the dataset to generate a boxplot.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# loading dataset
ds = sns.load_dataset('iris')

chevron_right


Step 3: Generate a boxplot using the boxplot() method.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# create boxplot object
ax = sns.boxplot(data=tips, orient="h")

chevron_right


Step 4: Seaborn boxplot() function has palette argument, in this example we have set palette=”Set1″, it uses a qualitative color paletter Set3 to color the boxes in boxpolot. So add palette parameter in boxplot method.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# use palette method
ax = sns.boxplot(data=ds, orient="h", palette="Set1")

chevron_right


Below is the complete program based on the above approach:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import libraries
import seaborn as sns
import matplotlib.pyplot as plt
  
# load datset
ds = sns.load_dataset("tips")
  
plt.figure(figsize=(8, 6))
  
# use palette method
ax = sns.boxplot(data=ds, orient="h", palette="Set1")

chevron_right


Output:

Coloring Boxplots with Seaborn Palettes


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :