Difference makes the DIFFERENCE
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes = True)
pen = sns.load_dataset('penguins')
pen.head(2)
sns.violinplot(x='island', y = 'flipper_length_mm',
split=True, inner = 'quartile', hue = 'sex', data = pen)
pen['bin_species'] = pen.species.apply(lambda x: "Gentoo" if x == "Gentoo" else 'Adelie | Chinstrap')
sns.violinplot(x = 'island', y='flipper_length_mm',
split = True, inner = 'quartile', hue='bin_species', data = pen)
pen.head(1)
sns.kdeplot(pen.flipper_length_mm, shade = True)
sns.kdeplot(pen[pen.species == 'Gentoo'].flipper_length_mm, shade = True)
sns.kdeplot(pen[pen.species == 'Gentoo'].flipper_length_mm, shade = True)
sns.kdeplot(pen[pen.species == 'Adelie'].flipper_length_mm, shade = True)
sns.kdeplot(pen[pen.species == 'Chinstrap'].flipper_length_mm, shade = True)
sns.kdeplot(pen[pen.species == 'Gentoo'].flipper_length_mm, shade = True)
sns.kdeplot(pen[pen.species == 'Adelie'].flipper_length_mm, shade = True)
sns.kdeplot(pen[pen.species == 'Chinstrap'].flipper_length_mm, shade = True)
plt.legend(title="Species", labels = ['Gentoo', "Adelie", "Chinstrap"])
sns.boxplot(pen[pen.species == 'Adelie'].flipper_length_mm)
sns.boxplot(pen[pen.species == 'Chinstrap'].flipper_length_mm)
sns.boxplot(pen[pen.species == 'Gentoo'].flipper_length_mm)
plt.legend(title="Species", labels = ['Gentoo', "Adelie", "Chinstrap"])
fig, axs = plt.subplots(nrows = 3)
sns.kdeplot(pen[pen.species == 'Gentoo'].flipper_length_mm, shade = True, ax=axs[0])
sns.kdeplot(pen[pen.species == 'Adelie'].flipper_length_mm, shade = True, ax=axs[1])
sns.kdeplot(pen[pen.species == 'Chinstrap'].flipper_length_mm, shade = True, ax=axs[2])
plt.legend(title="Species", labels = ['Gentoo', "Adelie", "Chinstrap"])
fig, axs = plt.subplots(nrows = 3)
sns.kdeplot(pen[pen.species == 'Gentoo'].flipper_length_mm, shade = True, ax=axs[0])
sns.kdeplot(pen[pen.species == 'Adelie'].flipper_length_mm, shade = True, ax=axs[1])
sns.kdeplot(pen[pen.species == 'Chinstrap'].flipper_length_mm, shade = True, ax=axs[2])
# plt.legend(title="Species", labels = ['Gentoo', "Adelie", "Chinstrap"])
plt.tight_layout()
fig, axs = plt.subplots(nrows = 3)
fig.set_size_inches(8, 6)
sns.kdeplot(pen[pen.species == 'Gentoo'].flipper_length_mm, shade = True, ax=axs[0])
sns.kdeplot(pen[pen.species == 'Adelie'].flipper_length_mm, shade = True, ax=axs[1])
sns.kdeplot(pen[pen.species == 'Chinstrap'].flipper_length_mm, shade = True, ax=axs[2])
# plt.legend(title="Species", labels = ['Gentoo', "Adelie", "Chinstrap"])
plt.tight_layout()
sns.boxplot(pen[pen.species == "Gentoo"].flipper_length_mm)
sns.boxplot(pen[pen.species == "Gentoo"].flipper_length_mm)
sns.boxplot(pen[pen.species == "Adelie"].flipper_length_mm)
sns.boxplot(pen[pen.species == "Chinstrap"].flipper_length_mm)
fig, axs = plt.subplots(nrows = 3)
fig.set_size_inches(6, 6)
sns.boxplot(pen[pen.species == "Gentoo"].flipper_length_mm, ax = axs[0])
sns.boxplot(pen[pen.species == "Adelie"].flipper_length_mm, ax = axs[1])
sns.boxplot(pen[pen.species == "Chinstrap"].flipper_length_mm, ax = axs[2])
plt.tight_layout()
pen.head(2)
col_name = 'species'
nrows = len(pen[col_name].unique())
fig, axs = plt.subplots(nrows=nrows)
fig.set_size_inches(6, 6)
j = 0
for i in pen[col_name].unique():
sns.boxplot(pen[pen.species == i].flipper_length_mm, ax = axs[j])
j += 1
plt.tight_layout()
col_name = 'species'
n = len(pen[col_name].unique())
print(n)
Link for further reference: https://seaborn.pydata.org/generated/seaborn.FacetGrid.html
g = sns.FacetGrid(pen, row = 'species')
g.map(sns.kdeplot, 'flipper_length_mm', shade=True)
g = sns.FacetGrid(pen, col = 'species')
g.map(sns.kdeplot, 'flipper_length_mm', shade=True)
g = sns.FacetGrid(pen, col = 'island')
g.map(sns.kdeplot, 'flipper_length_mm', shade=True)
g = sns.FacetGrid(pen, col = 'island')
g.map(sns.boxplot, 'flipper_length_mm')
g = sns.FacetGrid(pen, col = 'island')
g.map(sns.histplot, 'flipper_length_mm')
g = sns.FacetGrid(pen, col = 'island')
g.map(sns.distplot, 'flipper_length_mm')
g = sns.FacetGrid(pen, col = 'island', row='sex')
g.map(sns.histplot, 'flipper_length_mm')
g = sns.FacetGrid(pen, col = 'island', row='sex')
g.map(sns.violinplot, 'flipper_length_mm')
g = sns.FacetGrid(pen, col = 'island', row='sex', hue='species')
g.map(sns.violinplot, 'flipper_length_mm')
pen.head(2)
g = sns.FacetGrid(pen, col = 'island', row='sex', hue='species')
g.map(sns.scatterplot, 'flipper_length_mm', 'bill_length_mm')
g.add_legend()
g = sns.FacetGrid(pen, col = 'island', row='sex', hue='species')
g.map(sns.scatterplot, 'flipper_length_mm', 'bill_length_mm')
g.add_legend()
g.refline(y=pen['bill_length_mm'].median())