prettyplotlib.bar

The default matplotlib bar charts are okay, but they leave much to be desired.


In [1]:
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')



In [6]:
%load_ext autoreload
%autoreload 2


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-cbd125b6ada2> in <module>()
      1 get_ipython().magic(u'load_ext autoreload')
      2 get_ipython().magic(u'autoreload 2')
----> 3 import prettyplotlib

/Users/olga/workspace-git/prettyplotlib/prettyplotlib/__init__.py in <module>()
      2 
      3 from _bar import bar
----> 4 from _boxplot import boxplot
      5 from _hist import hist
      6 from _legend import legend

/Users/olga/workspace-git/prettyplotlib/prettyplotlib/_boxplot.py in <module>()
      3 import matplotlib as mpl
      4 import matplotlib.pyplot as plt
----> 5 from prettyplotlib import remove_chartjunk
      6 
      7 

ImportError: cannot import name remove_chartjunk
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

In [11]:
import prettyplotlib

In [1]:
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:


In [2]:
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')



In [3]:
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')



In [4]:
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')



In [5]:
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')



In [ ]: