Related Articles

Related Articles

Make Violinplot with data points using Seaborn
  • Last Updated : 25 Nov, 2020

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.

In this article, we will see how to make Violinplot and plot data points.

Method 1#: Using Inner attributes of violinplot

Example 1: Creating violinplot and use inner attributes. Inner Representation of the datapoints in the violin interior, If point or stick, show each underlying datapoint.

Syntax: seaborn.violinplot( x, y, data, inner = “points”)



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to illustrate
# violinplot using inbuilt data-set
# given in seaborn
    
# importing the required module
import seaborn 
  
# use to set style of background of plot
seaborn.set(style = 'whitegrid'
  
# loading data-set
tip = seaborn.load_dataset('tips')
plt.figure(figsize=(4,7))
  
seaborn.violinplot(x ='day', y ='tip',
                   data = tip,
                   inner="points")

chevron_right


Output:

Example 2:

We see the above implementation, let’s do the same thing for the “stick”. This option show data as lines on violin plot.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to illustrate
# violinplot using inbuilt data-set
# given in seaborn
    
# importing the required module
import seaborn 
  
# use to set style of background of plot
seaborn.set(style = 'whitegrid'
  
# loading data-set
tip = seaborn.load_dataset('tips')
plt.figure(figsize=(4,7))
  
seaborn.violinplot(x ='day', y ='tip',
                   data = tip,
                   inner="stick")

chevron_right


Output:



Example 3: 

Using quartile draw the quartiles of the distribution.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to illustrate
# violinplot using inbuilt data-set
# given in seaborn
    
# importing the required module
import seaborn 
  
# use to set style of background of plot
seaborn.set(style = 'whitegrid'
  
# loading data-set
tip = seaborn.load_dataset('tips')
plt.figure(figsize=(4,7))
  
seaborn.violinplot(x ='day', y ='tip'
                   data = tip,
                   inner="quartile")

chevron_right


Output:

Method 2#: Using swarmplot().

Using swaramplot we can show the data point inside in a violinplot.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to illustrate
# violinplot using inbuilt data-set
# given in seaborn
    
# importing the required module
import seaborn 
  
# use to set style of background of plot
seaborn.set(style = 'whitegrid'
  
# loading data-set
tip = seaborn.load_dataset('tips')
plt.figure(figsize=(4,7))
  
seaborn.violinplot(x ='day', y ='tip', data = tip)
seaborn.swarmplot(x ='day', y ='tip', data = tip,color= "white")

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
Recommended Articles
Page :