Chapter 2
Chapter 2
Styles
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Chris Moffitt
Instructor
Setting Styles
Seaborn has default configurations that can be applied with sns.set()
These styles can override matplotlib and pandas plots as well
sns.set()
df['Tuition'].plot.hist()
sns.set_style('white')
sns.displot(df['Tuition'])
sns.despine(left=True)
Chris Moffitt
Instructor
Defining a color for a plot
Seaborn supports assigning colors to plots using matplotlib color codes
sns.set(color_codes=True)
sns.displot(df['Tuition'], color='g')
sns.palplot(sns.color_palette("Blues", 12))
Chris Moffitt
Instructor
Matplotlib Axes
Most customization available through matplotlib Axes objects
Axes can be passed to seaborn functions
fig, ax = plt.subplots()
sns.histplot(df['Tuition'], ax=ax)
ax.set(xlabel='Tuition 2013-14')
fig, ax = plt.subplots()
sns.histplot(df['Tuition'], ax=ax)
ax.set(xlabel="Tuition 2013-14",
ylabel="Distribution", xlim=(0, 50000),
title="2013-14 Tuition and Fees Distribution")