Boxplot using Seaborn in Python

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas.

Box Plot

A box plot helps to maintain the distribution of quantitative data in such a way that it facilitates the comparisons between variables or across levels of a categorical variable. The main body of the box plot showing the quartiles and the median’s confidence intervals if enabled. The medians have horizontal lines at the median of each box and while whiskers have the vertical lines extending to the most extreme, non-outlier data points and caps are the horizontal lines at the ends of the whiskers.

Syntax: seaborn.boxplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, fliersize=5, linewidth=None, whis=1.5, ax=None, **kwargs)

Parameters:
x, y, hue: Inputs for plotting long-form data.
data: Dataset for plotting. If x and y are absent, this is interpreted as wide-form.
color: Color for all of the elements.

Returns: It returns the Axes object with the plot drawn onto it.



Example 1: Basic visualization of “fmri” dataset using violinplot()

filter_none

edit
close

play_arrow

link
brightness_4
code

import seaborn
      
      
seaborn.set(style = 'whitegrid'
fmri = seaborn.load_dataset("fmri"
      
seaborn.boxplot(x ="timepoint"
             y ="signal"
             data = fmri)

chevron_right


Output:

Example 2: Grouping data points on the basis of category, here as region and event.

filter_none

edit
close

play_arrow

link
brightness_4
code

import seaborn 
      
      
seaborn.set(style = 'whitegrid'
fmri = seaborn.load_dataset("fmri"
      
seaborn.boxplot(x ="timepoint"
             y ="signal"
             hue ="region"
             data = fmri) 

chevron_right


Output:

Example 3: Basic visualization of “tips” dataset using boxplot()

filter_none

edit
close

play_arrow

link
brightness_4
code

import seaborn 
      
      
seaborn.set(style = 'whitegrid')  
tip = seaborn.load_dataset('tips')
    
seaborn.boxplot(x ='day', y ='tip', data = tip)

chevron_right


Output:

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


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.