seaborn

Posted by neverset on October 11, 2020

figure-level function

fast solution to make a plot

axes-level function

solution to make arbitrarily complex plot

customerization

#oritinal implementation
import matplotlib.pyplot as plt
import seaborn as sns# Import data
df = sns.load_dataset('penguins').rename(columns={'sex': 'gender'})
sns.scatterplot(data=df, x='body_mass_g', y='bill_length_mm', 
            alpha=0.7, hue='species', size='gender')
#change default setting
# Change defaults
sns.set(style='whitegrid', context='talk', palette='rainbow')

suppress this text output is to use ; at the end of your plot

sns.scatterplot(data=df, x='body_mass_g', y='bill_length_mm', 
            alpha=0.7, hue='species', size='gender');

resize with plt.figure()

plt.figure(figsize=(9, 5))
sns.scatterplot(data=df, x='body_mass_g', y='bill_length_mm', 
            alpha=0.7, hue='species', size='gender');
plt.legend(loc='upper right', bbox_to_anchor=(1.2, 1));

change plot style sns.set_style()

# Change default style
sns.set_style('whitegrid')

change the context parameters with sns.set_context()

# Change default context
sns.set_context('talk')

customise the default colour palette with sns.set_palette()

#Change default palette
sns.set_palette('rainbow')
sns.set_palette(['green', 'purple', 'red'])