Skip to content

Commit

Permalink
finished boxplot
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelskens committed Apr 12, 2018
1 parent bbb7258 commit f6763f5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -5,4 +5,5 @@
opengrid/notebooks/index.html
dist/
build/
opengrid.egg-info/
opengrid.egg-info/
.DS_Store
54 changes: 54 additions & 0 deletions opengrid/library/plotting.py
@@ -1,5 +1,6 @@
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd


def plot_style():
Expand All @@ -13,4 +14,57 @@ def plot_style():
matplotlib.style.use('seaborn-deep')

plt.rcParams['figure.figsize'] = 16, 6

# To overrule the legend style
plt.rcParams['legend.facecolor'] = "#ffffff"
plt.rcParams['legend.frameon'] = True
plt.rcParams['legend.framealpha'] = 1

return plt


def boxplot(df, plot_mean=False, plot_ids=None):
"""
Plot boxplots
Plot the boxplots of a dataframe in time
Parameters
----------
df: Pandas Dataframe
Every collumn is a timeseries
plot_mean: bool
Wether or not to plot the means
plot_ids: [str]
List of id's to plot
Returns
-------
matplotlib figure
"""
description = df.apply(pd.DataFrame.describe, axis=1)

# plot
plt = plot_style()

df.index = df.index.map(lambda x: x.strftime('%b'))

df = df.T

fig, ax = plt.subplots()
axes, bp = df.boxplot(ax=ax, return_type='both')
plt.setp(bp['boxes'], color='black')
plt.setp(bp['whiskers'], color='black')

for id in plot_ids:
ax.scatter(x=axes.get_xticks(), y=df.loc[id], label=str(id))

if plot_mean:
ax.scatter(x=axes.get_xticks(), y=description['mean'], label="Mean", color='k', s=30, marker='+')

plt.xticks(rotation=45)

ax.legend()

return fig

0 comments on commit f6763f5

Please sign in to comment.