Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bccaca5

Browse files
committed
simplify poly array in example
svn path=/branches/v0_99_maint/; revision=7432
1 parent f415347 commit bccaca5

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

examples/api/histogram_path_demo.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,25 @@
2222
data = np.random.randn(1000)
2323
n, bins = np.histogram(data, 50)
2424

25-
2625
# get the corners of the rectangles for the histogram
2726
left = np.array(bins[:-1])
2827
right = np.array(bins[1:])
2928
bottom = np.zeros(len(left))
3029
top = bottom + n
31-
nrects = len(left)
32-
33-
XY = np.zeros((nrects, 4, 2))
34-
XY[:,0,0] = left
35-
XY[:,0,1] = bottom
36-
37-
XY[:,1,0] = left
38-
XY[:,1,1] = top
39-
40-
XY[:,2,0] = right
41-
XY[:,2,1] = top
42-
43-
XY[:,3,0] = right
44-
XY[:,3,1] = bottom
4530

4631

32+
# we need a (numrects x numsides x 2) numpy array for the path helper
33+
# function to build a compound path
34+
XY = np.array([[left,left,right,right], [bottom,top,top,bottom]]).T
4735

36+
# get the Path object
4837
barpath = path.Path.make_compound_path_from_polys(XY)
49-
print barpath.codes[:7], barpath.codes[-7:]
38+
39+
# make a patch out of it
5040
patch = patches.PathPatch(barpath, facecolor='blue', edgecolor='gray', alpha=0.8)
5141
ax.add_patch(patch)
5242

43+
# update the view limits
5344
ax.set_xlim(left[0], right[-1])
5445
ax.set_ylim(bottom.min(), top.max())
5546

0 commit comments

Comments
 (0)