use a class helper method to make the compound path from polys · feisuo/matplotlib@f415347 · GitHub
Skip to content

Commit f415347

Browse files
committed
use a class helper method to make the compound path from polys
svn path=/branches/v0_99_maint/; revision=7431
1 parent 6433e8e commit f415347

3 files changed

Lines changed: 56 additions & 30 deletions

File tree

examples/animation/histogram_tkagg.py

Lines changed: 8 additions & 7 deletions

examples/api/histogram_path_demo.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
# histogram our data with numpy
2222
data = np.random.randn(1000)
23-
n, bins = np.histogram(data, 100)
23+
n, bins = np.histogram(data, 50)
24+
2425

2526
# get the corners of the rectangles for the histogram
2627
left = np.array(bins[:-1])
@@ -29,28 +30,24 @@
2930
top = bottom + n
3031
nrects = len(left)
3132

32-
# here comes the tricky part -- we have to set up the vertex and path
33-
# codes arrays using moveto, lineto and closepoly
34-
35-
# for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the
36-
# CLOSEPOLY; the vert for the closepoly is ignored but we still need
37-
# it to keep the codes aligned with the vertices
38-
nverts = nrects*(1+3+1)
39-
verts = np.zeros((nverts, 2))
40-
codes = np.ones(nverts, int) * path.Path.LINETO
41-
codes[0::5] = path.Path.MOVETO
42-
codes[4::5] = path.Path.CLOSEPOLY
43-
verts[0::5,0] = left
44-
verts[0::5,1] = bottom
45-
verts[1::5,0] = left
46-
verts[1::5,1] = top
47-
verts[2::5,0] = right
48-
verts[2::5,1] = top
49-
verts[3::5,0] = right
50-
verts[3::5,1] = bottom
51-
52-
barpath = path.Path(verts, codes)
53-
patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5)
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
45+
46+
47+
48+
barpath = path.Path.make_compound_path_from_polys(XY)
49+
print barpath.codes[:7], barpath.codes[-7:]
50+
patch = patches.PathPatch(barpath, facecolor='blue', edgecolor='gray', alpha=0.8)
5451
ax.add_patch(patch)
5552

5653
ax.set_xlim(left[0], right[-1])

lib/matplotlib/path.py

Lines changed: 28 additions & 0 deletions

0 commit comments

Comments
 (0)