prettyplotlib.boxplot

The original matplotlib boxplots are okay, but their lines are too thick and the blues and reds are a little garish.


In [1]:
import matplotlib.pyplot as plt
np.random.seed(10)

data = np.random.randn(8, 4)
labels = ['A', 'B', 'C', 'D']

fig, ax = plt.subplots()
ax.boxplot(data)
ax.set_xticklabels(labels)
fig.savefig('boxplot_matplotlib_default.png')


In prettyplotlib, we did the usual softening of the blacks and removing of the axes. We also changed the colors of the boxplot, which is actually really annoying to do by hand:

import brewer2mpl
set1 = brewer2mpl.get_map('Set1', 'qualitative', 7).mpl_colors

bp = ax.boxplot(x, **kwargs)
plt.setp(bp['boxes'], color=set1[1], linewidth=0.5)
plt.setp(bp['medians'], color=set1[0])
plt.setp(bp['whiskers'], color=set1[1], linestyle='solid', linewidth=0.5)
plt.setp(bp['fliers'], color=set1[1])
plt.setp(bp['caps'], color='none')

So using prettyplotlib.boxplot is much easier.


In [7]:
import prettyplotlib as ppl
import matplotlib as mpl

np.random.seed(10)

data = np.random.randn(8, 4)
labels = ['A', 'B', 'C', 'D']

fig, ax = plt.subplots()
ppl.boxplot(ax, data, xticklabels=labels)
fig.savefig('boxplot_prettyplotlib_default.png')


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-161734915b21> in <module>()
      8 
      9 fig, ax = plt.subplots()
---> 10 ppl.boxplot(ax, data, xticklabels=labels)
     11 fig.savefig('boxplot_prettyplotlib_default.png')

/Users/olga/workspace-git/prettyplotlib/prettyplotlib/_boxplot.py in boxplot(*args, **kwargs)
     19     @return:
     20     """
---> 21     ax, args, kwargs = maybe_get_ax(args, kwargs)
     22     # If no ticklabels are specified, don't draw any
     23     xticklabels = kwargs.pop('xticklabels', None)

/Users/olga/workspace-git/prettyplotlib/prettyplotlib/utils.py in maybe_get_ax(args, kwargs)
     80     """
     81     if isinstance(args[0], mpl.axes.Axes):
---> 82         ax = args[0]
     83         args = args[1:]
     84     elif 'ax' in kwargs:

AttributeError: 'tuple' object has no attribute 'pop'

In [ ]: