Ridgeline plots using seaborn
Based on the following seaborn gallery example:
Overlapping densities (‘ridge plot’) — seaborn 0.11.0 documentation
def ridgeline(df, x, row, height=1, aspect=8, hue=None, hspace=-.25, label_fmt='{x}',
map_func=sns.kdeplot, fill=True, lw=0, alpha=1, **map_kwargs):
def label_func(data, color, label):
ax = plt.gca()
label = label_fmt.format(x=label)
ax.text(0, 0, label, ha='left', va='bottom', transform=ax.transAxes)
with sns.axes_style(style='white', rc={'axes.facecolor': (0, 0, 0, 0)}):
g = sns.FacetGrid(df, row=row, hue=hue, height=height, aspect=aspect)
g.map_dataframe(map_func, x=x, fill=fill, lw=lw, alpha=alpha, **map_kwargs)
g.map_dataframe(label_func)
g.fig.subplots_adjust(hspace=hspace)
g.set_titles('')
g.set(yticks=[])
g.despine(left=True)
return g