In [1]:
import numpy
from matplotlib import pyplot
%matplotlib inline
### a simple histogram of random Gaussian data
mu = 100
sigma = 20
data = mu + sigma * numpy.random.randn(1000)
fig, ax = pyplot.subplots()
h = ax.hist(data)
In [2]:
fig, ax = pyplot.subplots()
h = ax.hist(data, orientation='horizontal')
In [3]:
fig, ax = pyplot.subplots()
h = ax.hist(data, histtype='stepfilled', color='orange', range=(10,200), bins=30)
In [4]:
fig, ax = pyplot.subplots()
h = ax.hist(data, histtype='step', lw=2, color='orange', bins=1000, cumulative=True, normed=True)
In [5]:
### some extra stuff
fig, (ax1, ax2) = pyplot.subplots(nrows=1, ncols=2, figsize=(8, 3))
h1 = ax1.hist(data, histtype='stepfilled', color='orange', range=(10,200), bins=30, normed=True)
h2 = ax2.hist(data, histtype='step', lw=2, color='orange', bins=1000, cumulative=True, normed=True)
ax1.set_title('my regular histogram')
ax2.set_title('my cumulative histogram')
ax1.set_xlabel('xdata')
ax2.set_xlabel('xdata')
ax1.set_ylabel('probability')
ax2.set_ylabel('cumulative probability')
ax1.minorticks_on()
ax2.grid(color='gray', ls=':', lw=1)
In [6]:
### have we gone too far?
fig = pyplot.figure(figsize=(8, 6))
ax_top = pyplot.subplot2grid((3, 3), (0, 0), rowspan=1, colspan=2)
ax_right = pyplot.subplot2grid((3, 3), (1, 2), rowspan=2, colspan=1)
ax_center = pyplot.subplot2grid((3, 3), (1, 0), rowspan=2, colspan=2, sharex=ax_top, sharey=ax_right)
fig.subplots_adjust(hspace=0, wspace=0)
xdata = numpy.random.randn(200)
ydata = xdata + numpy.random.randn(200)
ax_center.plot(xdata, ydata, ls='', marker='^', ms=6, color='r', mec='b', mew=1, label='my data')
h1 = ax_top.hist(xdata, histtype='stepfilled', bins=20, lw=2, ec='gray', fc='b', alpha=0.5)
h2 = ax_right.hist(ydata, histtype='stepfilled', bins=20, lw=2, ec='gray', fc='r', alpha=0.5, orientation='horizontal')
ax_center.legend(loc='upper left', numpoints=2)
Out[6]:
In [ ]: