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

Skip to content

Commit 16ec843

Browse files
committed
updated path example
svn path=/trunk/matplotlib/; revision=5322
1 parent f80dba2 commit 16ec843

2 files changed

Lines changed: 28 additions & 27 deletions

File tree

examples/api/path_patch_demo.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,28 @@
99
ax = fig.add_subplot(111)
1010

1111
pathdata = [
12-
(Path.MOVETO, (0, 0)),
13-
(Path.CURVE4, (-1, 0)),
14-
(Path.CURVE4, (-1, 1)),
15-
(Path.CURVE4, (0, 1)),
16-
(Path.LINETO, (2, 1)),
17-
(Path.CURVE4, (3, 1)),
18-
(Path.CURVE4, (3, 0)),
19-
(Path.CURVE4, (2, 0)),
20-
(Path.CLOSEPOLY, (0, 0)),
12+
(Path.MOVETO, (1.58, -2.57)),
13+
(Path.CURVE4, (0.35, -1.1)),
14+
(Path.CURVE4, (-1.75, 2.0)),
15+
(Path.CURVE4, (0.375, 2.0)),
16+
(Path.LINETO, (0.85, 1.15)),
17+
(Path.CURVE4, (2.2, 3.2)),
18+
(Path.CURVE4, (3, 0.05)),
19+
(Path.CURVE4, (2.0, -0.5)),
20+
(Path.CLOSEPOLY, (1.58, -2.57)),
2121
]
2222

2323
codes, verts = zip(*pathdata)
2424
path = mpath.Path(verts, codes)
25-
patch = mpatches.PathPatch(path, facecolor='green', edgecolor='yellow', alpha=0.5)
25+
patch = mpatches.PathPatch(path, facecolor='red', edgecolor='yellow', alpha=0.5)
2626
ax.add_patch(patch)
2727

28-
29-
ax.set_xlim(-5,5)
30-
ax.set_ylim(-5,5)
31-
28+
x, y = zip(*path.vertices)
29+
line, = ax.plot(x, y, 'go-')
30+
ax.grid()
31+
ax.set_xlim(-3,4)
32+
ax.set_ylim(-3,4)
33+
ax.set_title('spline paths')
3234
plt.show()
3335

3436

examples/event_handling/path_editor.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
ax = fig.add_subplot(111)
1111

1212
pathdata = [
13-
(Path.MOVETO, (0, 0)),
14-
(Path.CURVE4, (-1, 0.1)),
15-
(Path.CURVE4, (-1, 0.9)),
16-
(Path.CURVE4, (0, 1)),
17-
(Path.LINETO, (2, 1)),
18-
(Path.CURVE4, (3, 0.9)),
19-
(Path.CURVE4, (3, 0.1)),
20-
(Path.CURVE4, (2, 0)),
21-
(Path.CLOSEPOLY, (0, 0)),
13+
(Path.MOVETO, (1.58, -2.57)),
14+
(Path.CURVE4, (0.35, -1.1)),
15+
(Path.CURVE4, (-1.75, 2.0)),
16+
(Path.CURVE4, (0.375, 2.0)),
17+
(Path.LINETO, (0.85, 1.15)),
18+
(Path.CURVE4, (2.2, 3.2)),
19+
(Path.CURVE4, (3, 0.05)),
20+
(Path.CURVE4, (2.0, -0.5)),
21+
(Path.CLOSEPOLY, (1.58, -2.57)),
2222
]
2323

2424
codes, verts = zip(*pathdata)
@@ -123,9 +123,8 @@ def motion_notify_callback(self, event):
123123
if event.button != 1: return
124124
x,y = event.xdata, event.ydata
125125

126-
# todo: expose me
127126
vertices = self.pathpatch.get_path().vertices
128-
127+
129128
vertices[self._ind] = x,y
130129
self.line.set_data(zip(*vertices))
131130

@@ -137,8 +136,8 @@ def motion_notify_callback(self, event):
137136

138137
interactor = PathInteractor(patch)
139138
ax.set_title('drag vertices to update path')
140-
ax.set_xlim(-5,5)
141-
ax.set_ylim(-5,5)
139+
ax.set_xlim(-3,4)
140+
ax.set_ylim(-3,4)
142141

143142
plt.show()
144143

0 commit comments

Comments
 (0)