prettyplotlib.hist
¶The default matplotlib
histogram isn't that bad, but it leaves much to be desired.
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
fig, ax = plt.subplots(1)
ax.hist(np.random.randn(1000))
fig.savefig('hist_matplotlib_default.png')
And if you add a grid, it looks pretty gross.
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
fig, ax = plt.subplots(1)
ax.hist(np.random.randn(1000))
ax.grid(True)
fig.savefig('hist_matplotlib_grid.png')
With prettyplotlib.hist
, we make the outlines of the rectangles white, remove the top and right axis lines, thin out the remaining axis lines, and change the blacks from regular black to a light grey (#262626)
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
fig, ax = plt.subplots(1)
ppl.hist(np.random.randn(1000))
fig.savefig('hist_prettyplotlib_default.png')
And you can add a grid over the $y$-axis if you like. It's "erasing" some of the figure, but it's actually adding information, since it shows the tick lines!
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
fig, ax = plt.subplots(1)
# 'y' for the 'y' axis. Could also add a grid over the 'x' axis.
ppl.hist(ax, np.random.randn(1000), grid='y')
fig.savefig('hist_prettyplotlib_grid.png')
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
fig, ax = plt.subplots(1)
# 'y' for the 'y' axis. Could also add a grid over the 'x' axis.
ppl.hist(ax, np.random.randn(1000), grid='y')
fig.savefig('hist_prettyplotlib_grid.png')
%load_ext autoreload
%autoreload 2
The autoreload extension is already loaded. To reload it, use: %reload_ext autoreload
%pdb
Automatic pdb calling has been turned ON
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
fig, ax = ppl.subplots()
# 'y' for the 'y' axis. Could also add a grid over the 'x' axis.
for i in range(2):
ppl.hist(np.random.randn(1000), grid='y')
fig.savefig('hist_prettyplotlib_two_datasets.png')
ax._get_lines.color_cycle
<itertools.cycle at 0x10f1a1fc8>
print [(k,v) for k,v in ax.__dict__.iteritems() if 'cycle' in k]
[]