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

Skip to content

Commit 0a3ffe1

Browse files
committed
Fix poly_editor.py
svn path=/trunk/matplotlib/; revision=4878
1 parent f0231dc commit 0a3ffe1

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

examples/poly_editor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, ax, poly):
3737

3838
x, y = zip(*self.poly.xy)
3939
self.line = Line2D(x,y,marker='o', markerfacecolor='r', animated=True)
40+
self.ax.add_line(self.line)
4041
#self._update_line(poly)
4142

4243
cid = self.poly.add_callback(self.poly_changed)
@@ -106,14 +107,17 @@ def key_press_callback(self, event):
106107
self.poly.xy = [tup for i,tup in enumerate(self.poly.xy) if i!=ind]
107108
self.line.set_data(zip(*self.poly.xy))
108109
elif event.key=='i':
109-
xys = self.poly.get_transform().seq_xy_tups(self.poly.xy)
110+
xys = self.poly.get_transform().transform(self.poly.xy)
110111
p = event.x, event.y # display coords
111112
for i in range(len(xys)-1):
112113
s0 = xys[i]
113114
s1 = xys[i+1]
114115
d = dist_point_to_segment(p, s0, s1)
115116
if d<=self.epsilon:
116-
self.poly.xy.insert(i+1, (event.xdata, event.ydata))
117+
self.poly.xy = npy.array(
118+
list(self.poly.xy[:i]) +
119+
[(event.xdata, event.ydata)] +
120+
list(self.poly.xy[i:]))
117121
self.line.set_data(zip(*self.poly.xy))
118122
break
119123

@@ -130,7 +134,7 @@ def motion_notify_callback(self, event):
130134

131135
self.poly.xy[self._ind] = x,y
132136
self.line.set_data(zip(*self.poly.xy))
133-
137+
134138
self.canvas.restore_region(self.background)
135139
self.ax.draw_artist(self.poly)
136140
self.ax.draw_artist(self.line)

0 commit comments

Comments
 (0)