3
import matplotlib.pyplot as plt
4
import matplotlib.patches as patches
5
import matplotlib.path as path
8
ax = fig.add_subplot(111)
10
# histogram our data with numpy
11
data = np.random.randn(1000)
12
n, bins = np.histogram(data, 100)
14
# get the corners of the rectangles for the histogram
15
left = np.array(bins[:-1])
16
right = np.array(bins[1:])
17
bottom = np.zeros(len(left))
21
nverts = nrects*(1+3+1)
22
verts = np.zeros((nverts, 2))
23
codes = np.ones(nverts, int) * path.Path.LINETO
24
codes[0::5] = path.Path.MOVETO
25
codes[4::5] = path.Path.CLOSEPOLY
27
verts[0::5,1] = bottom
33
verts[3::5,1] = bottom
35
barpath = path.Path(verts, codes)
36
patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5)
39
ax.set_xlim(left[0], right[-1])
40
ax.set_ylim(bottom.min(), top.max())