-
wbdata 5
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
Lecture1.5
-
-
Hexbin Plots 7
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
Lecture2.5
-
Lecture2.6
-
Lecture2.7
-
-
Heatmap 5
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
Lecture3.5
-
-
Boxplot 2
-
Lecture4.1
-
Lecture4.2
-
-
Violin Plot 5
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
-
Time Series 2
-
Lecture6.1
-
Lecture6.2
-
-
Pairplot 2
-
Lecture7.1
-
Lecture7.2
-
-
Kernel Density Estimation 3
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
Violin Plot
Let’s import the same data as last lesson.
import wbdata
import pandas as pd
countries = ["AFR","CHN","USA","DNK","FRA","LBN","LKA","LUX"]
import datetime
df = wbdata.get_dataframe({'NY.GDP.MKTP.KD.ZG': 'GDP Rate'}, country=countries)
df = df.unstack("country")
df.columns = df.columns.droplevel()
df
Seaborn uses violinplot() for plotting, you just need to give the data as an argument.
import seaborn as sns
import matplotlib.pyplot as plt
sns.violinplot(data=df)
plt.title("GDP Growth Rate")
plt.show()
Let’s restrict values to -10 to 20.
sns.violinplot(data=df[(df < 20) & (df > -10)])
plt.title("GDP Growth Rate")
plt.show()
We can use inner=”quart” to set up quarter lines in the violin plot.
sns.violinplot(data=df[(df < 20) & (df > -10)],inner="quart")
plt.title("GDP Growth Rate")
plt.show()
We can also plot a swarmplot over the violin plot by setting inner=None on the violin plot and using a swarmplot after.
Challenge
Try this for yourself.
Prev
Introduction
Next
Violin Plot Part 2