prettyplotlib.bar
¶The default matplotlib
bar charts are okay, but they leave much to be desired.
import matplotlib.pyplot as plt
import numpy as np
import string
fig, ax = plt.subplots(1)
np.random.seed(14)
ax.bar(np.arange(10), np.abs(np.random.randn(10)))
fig.savefig('bar_matplotlib_default.png')
%load_ext autoreload
%autoreload 2
import prettyplotlib
import prettyplotlib as ppl
import matplotlib.pyplot as plt
from pandas.util.testing import rands
fig, ax = plt.subplots(1)
np.random.seed(14)
ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)))
fig.savefig('bar_prettyplotlib_default.png')
And as with prettyplotlib.hist
, you can also add a grid:
import prettyplotlib as ppl
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1)
np.random.seed(14)
# 'y' for make a grid based on where the major ticks are on the y-axis
ppl.bar(ax, np.arange(10), np.abs(np.random.randn(10)), grid='y')
fig.savefig('bar_prettyplotlib_grid.png')
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
import string
fig, ax = plt.subplots(1)
np.random.seed(14)
n = 10
ppl.bar(ax, np.arange(n), np.abs(np.random.randn(n)), annotate=True, grid='y')
fig.savefig('bar_prettyplotlib_grid_annotated.png')
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
import string
fig, ax = plt.subplots(1)
np.random.seed(14)
n = 10
ppl.bar(ax, np.arange(n), np.abs(np.random.randn(n)),
annotate=range(n,2*n), grid='y')
fig.savefig('bar_prettyplotlib_grid_annotated_user.png')
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
import string
fig, ax = plt.subplots(1)
np.random.seed(14)
n = 10
ppl.bar(ax, np.arange(n), np.abs(np.random.randn(n)), annotate=True, xticklabels=string.uppercase[:n], grid='y')
fig.savefig('bar_prettyplotlib_grid_annotated_labeled.png')