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

Skip to content

Commit 45566be

Browse files
committed
added compound path demo
svn path=/trunk/matplotlib/; revision=7021
1 parent 0b125cc commit 45566be

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

examples/api/complex_path.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Make a compund path -- in this case two simple polygons, a rectangle
3+
and a triangle. Use CLOSEOPOLY and MOVETO for the different parts of
4+
the compound path
5+
"""
6+
import numpy as np
7+
from matplotlib.path import Path
8+
from matplotlib.patches import PathPatch
9+
import matplotlib.pyplot as plt
10+
11+
12+
vertices = []
13+
codes = []
14+
15+
codes = [Path.MOVETO] + [Path.LINETO]*3 + [Path.CLOSEPOLY]
16+
vertices = [(1,1), (1,2), (2, 2), (2, 1), (0,0)]
17+
18+
codes += [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]
19+
vertices += [(4,4), (5,5), (5, 4), (0,0)]
20+
21+
vertices = np.array(vertices, float)
22+
path = Path(vertices, codes)
23+
24+
pathpatch = PathPatch(path, facecolor='red', edgecolor='green')
25+
26+
fig = plt.figure()
27+
ax = fig.add_subplot(111)
28+
ax.add_patch(pathpatch)
29+
ax.set_title('A compound path')
30+
31+
ax.dataLim.update_from_data_xy(vertices)
32+
ax.autoscale_view()
33+
34+
35+
plt.show()

0 commit comments

Comments
 (0)