import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')
df
vars = df.columns.values.tolist()
vars
# make a box plot of the iris species
sns.boxplot(y=vars[0], data=df)
plt.show()
# set a grey background color
sns.set_style("darkgrid")
# and create the box plot again to see the difference
sns.boxplot(y=vars[0], data=df)
plt.show()
sns.boxplot(x='species', y=df[vars[0]], data=df)
plt.ylabel(vars[0])
plt.show()
# add stripplot to the box plot
sns.boxplot(x='species', y=df[vars[0]], data=df)
plt.ylabel(vars[0])
sns.stripplot(x='species', y=df[vars[0]], data=df, jitter=True, size=3, color='black') # color black allow to see the difference
plt.show()
#make a violin plot of all rows in a dataframe column
sns.violinplot(y=df[vars[0]])
#set up y label
plt.ylabel(vars[0])
plt.show()
# Group variables by species
sns.violinplot(x='species', y=df[vars[0]], data=df)
plt.ylabel(vars[0])
plt.show()
fig, axs = plt.subplots(1, len(vars)-1, figsize=(15,5))
for i in range(0,len(vars)-1):
sns.violinplot(x='species', y=df[vars[i]], data=df,ax=axs[i])
axs[i].set_ylabel(vars[i])
plt.show()
fig, axs = plt.subplots(2, len(vars)-1, figsize=(20,10))
for i in range(0,len(vars)-1):
sns.violinplot(x='species', y=df[vars[i]], data=df,ax=axs[0,i])
axs[0,i].set_ylabel(vars[i])
for i in range(0,len(vars)-1):
sns.boxplot(x='species', y=df[vars[i]], data=df,ax=axs[1,i])
axs[1,i].set_ylabel(vars[i])
sns.stripplot(x='species', y=df[vars[i]], data=df, jitter=True, size=3, color='black', ax=axs[1,i])
plt.show()
fig.savefig('front.png')