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

Voilin Plot

A violin plot plays a similar activity that is pursued through whisker or box plot do. As it shows several quantitative data across one or more categorical variables. It can be an effective and attractive way to show multiple data at several units. A “wide-form” Data Frame helps to maintain each numeric column which can be plotted on the graph. It is possible to use NumPy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes.

Syntax: seaborn.violinplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, bw=’scott’, cut=2, scale=’area’, scale_hue=True, gridsize=100, width=0.8, inner=’box’, split=False, dodge=True, orient=None, linewidth=None, color=None, palette=None, saturation=0.75, ax=None, **kwargs)

Parameters:
x, y, hue: Inputs for plotting long-form data.
data: Dataset for plotting.
scale: The method used to scale the width of each violin.

Returns: This method 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.violinplot(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.violinplot(x ="timepoint"
             y ="signal"
             hue ="region"
             style ="event"
             data = fmri) 

chevron_right


Output:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:




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.