In [1]:
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import seaborn as sns
In [2]:
import sys
print(sys.version)
In [3]:
!python --version
In [4]:
dataframe = pd.DataFrame({'age':[1.,2,3,4,5,6,7,8,9],
'height':[4, 4.5, 5, 6, 7, 8, 9, 9.5, 10],
'gender':['M','F', 'F','M','M','F', 'F','M', 'F'],
#'hair color':['brown','black', 'brown', 'blonde', 'brown', 'red',
# 'brown', 'brown', 'black' ],
'hair length':[1,6,2,3,1,5,6,5,3] })
In [5]:
dataframe
Out[5]:
You can pass seaborn color palettes of RGB values.
For example:
In [6]:
sns.color_palette(palette="Blues_d", n_colors=9, desat=None)
Out[6]:
The following plot uses a seaborn-derived color pallette. See below for info about how to make, modify, and view them.
In [7]:
def plot_data():
color_palette = sns.color_palette(palette="Blues_d", n_colors=9, desat=None)
g = sns.FacetGrid(dataframe, col="gender", hue='height', palette=color_palette)
g = (g.map(plt.scatter, "age", 'hair length', edgecolor="w").add_legend())
plot_data()
In [8]:
# change seaborn style
sns.set(style="ticks")
# re-make the plot with this setting.
plot_data()
Add some settings to matplotlib to get bigger fonts.
Note: not all of their suggestions are appropriate for my distribution/needs.
In [9]:
# settings from I heart pandas:
# https://github.com/fredhutchio/i-heart-pandas/blob/master/3-pandas.ipynb
mpl.rcParams.update({
'font.size': 16, 'axes.titlesize': 17, 'axes.labelsize': 15,
'xtick.labelsize': 10, 'ytick.labelsize': 13,
#'font.family': 'Lato', # I don't have this font family
'font.weight': 600,
'axes.labelweight': 600, 'axes.titleweight': 600,
#'figure.autolayout': True # screws up layout for seaborn facetgrid objects.
})
In [10]:
# re-make the plot with this setting.
plot_data()
In [11]:
# a sample seaborn-created color palette:
# http://stanford.edu/~mwaskom/software/seaborn-dev/tutorial/color_palettes.html
sns.diverging_palette(145, 280, s=85, l=25, n=7)
Out[11]:
Seaborn also comes with a function called palplot, which can display color palettes.
In [12]:
sns.palplot(sns.diverging_palette(145, 280, s=85, l=25, n=7))
Since the palettes are just lists of list, you can path them together as you like.
In [13]:
sns.palplot(sns.diverging_palette(145, 280, s=85, l=25, n=7)[0:5] +
sns.diverging_palette(220, 20, n=7)[4:])
In [ ]: