contents
-
styling figures with axes_style() and set_style()
-
removing spines with despine()
-
temporarity setting figure style
-
overriding element of the seaborn styles
-
scaling plot elements with plotting_context() and set_context()
code
-
import
%matplotlib inline import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt # 1069 is sum(map(ord, 'aesthetics)) np.random.seed(sum(map(ord, 'aesthetics'))) def sinplot(flip=1): x = np.linspace(0, 14, 100) for i in range(1, 7): plt.plot(x, np.sin(x + i * .5) * (7 - i) * flip) sinplot()
-
import seaborn
import seaborn as sns sinplot()
styling figures with axes_style() and set_style()
-
preset seaborn themes
-
darkgrid => default
-
whitegrid
-
dark
-
white
-
ticks
-
-
whitegrid
sns.set_style('whitegrid') data = np.random.normal(size=(20, 6)) + np.arange(6) / 2 sns.boxplot(data)
-
dark
sns.set_style('dark') sinplot()
-
white
sns.set_style('white') sinplot()
-
ticks
sns.set_style('ticks') sinplot()
removing spines with despine()
-
both
white
andticks
styles can benefit from removing the top and right axes splines -
through the matplotlib parameters or call
despine()
-
code
sinplot() sns.despine()
-
trim range
# offsetting the spines away form the data # `trim` will limit the range of the surviving spines f, ax = plt.subplots() sns.violinplot(data) sns.despine(offset=10, trim=True)
-
control which spines are removed
# control which spines are removed sns.set_style('whitegrid') sns.boxplot(data, color='deep') sns.despine(left=True)
temporarity setting figure style
-
use
axes_style()
function in awith
statement to temporarily set plot parameterswith sns.axes_style('darkgrid'): plt.subplot(211) sinplot() plt.subplot(212) sinplot(-1)
overriding element of the seaborn styles
- pass a dictionary of parameters to the
rc
argument
-
get parameters
# get parameters sns.axes_style() {'axes.axisbelow': True, 'axes.edgecolor': '.8', 'axes.facecolor': 'white', 'axes.grid': True, 'axes.labelcolor': '.15', 'axes.linewidth': 1.0, 'font.family': [u'sans-serif'], 'font.sans-serif': [u'Arial', u'Liberation Sans', u'Bitstream Vera Sans', u'sans-serif'], 'grid.color': '.8', 'grid.linestyle': u'-', 'image.cmap': u'Greys', 'legend.frameon': False, 'legend.numpoints': 1, 'legend.scatterpoints': 1, 'lines.solid_capstyle': u'round', 'text.color': '.15', 'xtick.color': '.15', 'xtick.direction': u'out', 'xtick.major.size': 0.0, 'xtick.minor.size': 0.0, 'ytick.color': '.15', 'ytick.direction': u'out', 'ytick.major.size': 0.0, 'ytick.minor.size': 0.0}
-
set parameters
# then set different versions of these parameters sns.set_style('darkgrid', {'grid.linewidth': .5, 'axes.facecolor': '.9'}) sinplot()
scaling plot elements with plotting_context() and set_context()
-
preset scaling
-
paper
-
notebook => default
-
talk
-
poster
-
-
reset
# reset the default parameters sns.set()
-
paper
sns.set_context('paper') plt.figure(figsize=(8, 6)) sinplot()
-
talk
sns.set_context('talk') plt.figure(figsize=(8, 6)) sinplot()
-
poster
sns.set_context('paper') plt.figure(figsize=(8, 6)) sinplot()
-
notebook
sns.set_context('notebook', font_scale=1.5, rc={'line.linewidth': 2.5}) sinplot()