Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Violinplot | Categorical Plot Types
Deep Dive into the seaborn Visualization

book
Violinplot

A violinplot is a hybrid of a box plot and a kernel density plot, which shows peaks in the data. It is used to visualize the distribution of numerical data. Unlike a box plot that can only show summary statistics, violin plots depict summary statistics and the density of each variable.

carousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-img
Tâche

Swipe to start coding

  1. Create a violinplot using the g variable:
  • Set the x parameter equals the 'day';
  • Set the y parameter equals the 'total_bill';
  • Set the hue parameter equals 'sex';
  • Set the 'rocket' palette;
  • Set the split parameter;
  • Set the inner parameter equals the 'point';
  • Set the bw parameter equals the 0.2.
  1. Set the title for the plot: 'Tips violinplot'.

Solution

import warnings

# Ignore all warnings
warnings.filterwarnings('ignore')

# Importing libraries needed
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/tips.csv')

# Create a violinplot using the g variable
g = sns.violinplot(# Set the x
x = 'day',
# Set the y
y = 'total_bill',
# Set the hue
hue = 'sex',
# Set the palette
palette = 'rocket',
# Set the split
split = True,
# Set the inner
inner = 'point',
# Set the bw
bw = 0.2,
# Setting the data
data = df)

# Set the title for the plot
g.set_title('Tips violinplot')
# Displaying the plot
plt.show()

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 4
import warnings

# Ignore all warnings
warnings.filterwarnings('ignore')

# Importing libraries needed
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/tips.csv')

# Create a violinplot using the g variable
g = ___(# Set the x
___,
# Set the y
___,
# Set the hue
hue = '___',
# Set the palette
___,
# Set the split
___,
# Set the inner
inner = '___',
# Set the bw
bw = ___,
# Setting the data
data = df)

# Set the title for the plot
g.___('Tips violinplot')
# Displaying the plot
plt.show()
toggle bottom row
some-alt