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 [2]:
%load_ext autoreload
%autoreload 2
In [3]:
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')
As of v0.1.4, this also works without an ax
as the first argument!!
In [4]:
ppl.boxplot(data, xticklabels=labels)
Out[4]:
In [ ]: