Skip to content

Instantly share code, notes, and snippets.

@luiscape
Created December 11, 2017 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luiscape/e43cfd834d5704b5a6fd54996c20c3d2 to your computer and use it in GitHub Desktop.
Save luiscape/e43cfd834d5704b5a6fd54996c20c3d2 to your computer and use it in GitHub Desktop.
Plots facets using Seaborn
#
# From Seaborn's official documentation:
#
# https://seaborn.pydata.org/generated/seaborn.FacetGrid.html
#
>>> import pandas as pd
>>> df = pd.DataFrame(
... data=np.random.randn(90, 4),
... columns=pd.Series(list("ABCD"), name="walk"),
... index=pd.date_range("2015-01-01", "2015-03-31",
... name="date"))
>>> df = df.cumsum(axis=0).stack().reset_index(name="val")
>>> def dateplot(x, y, **kwargs):
... ax = plt.gca()
... data = kwargs.pop("data")
... data.plot(x=x, y=y, ax=ax, grid=False, **kwargs)
>>> g = sns.FacetGrid(df, col="walk", col_wrap=2, size=3.5)
>>> g = g.map_dataframe(dateplot, "date", "val")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment