|
4 | 4 | ===========
|
5 | 5 |
|
6 | 6 | This is an example to show how to build cross-GUI applications using
|
7 |
| -matplotlib event handling to interact with objects on the canvas. |
| 7 | +Matplotlib event handling to interact with objects on the canvas. |
8 | 8 | """
|
9 | 9 | import numpy as np
|
10 | 10 | from matplotlib.lines import Line2D
|
@@ -33,17 +33,19 @@ class PolygonInteractor(object):
|
33 | 33 |
|
34 | 34 | def __init__(self, ax, poly):
|
35 | 35 | if poly.figure is None:
|
36 |
| - raise RuntimeError('You must first add the polygon to a figure or canvas before defining the interactor') |
| 36 | + raise RuntimeError('You must first add the polygon to a figure ' |
| 37 | + 'or canvas before defining the interactor') |
37 | 38 | self.ax = ax
|
38 | 39 | canvas = poly.figure.canvas
|
39 | 40 | self.poly = poly
|
40 | 41 |
|
41 | 42 | x, y = zip(*self.poly.xy)
|
42 |
| - self.line = Line2D(x, y, marker='o', markerfacecolor='r', animated=True) |
| 43 | + self.line = Line2D(x, y, |
| 44 | + marker='o', markerfacecolor='r', |
| 45 | + animated=True) |
43 | 46 | self.ax.add_line(self.line)
|
44 |
| - #self._update_line(poly) |
45 | 47 |
|
46 |
| - cid = self.poly.add_callback(self.poly_changed) |
| 48 | + self.cid = self.poly.add_callback(self.poly_changed) |
47 | 49 | self._ind = None # the active vert
|
48 | 50 |
|
49 | 51 | canvas.mpl_connect('draw_event', self.draw_callback)
|
@@ -112,7 +114,9 @@ def key_press_callback(self, event):
|
112 | 114 | elif event.key == 'd':
|
113 | 115 | ind = self.get_ind_under_point(event)
|
114 | 116 | if ind is not None:
|
115 |
| - self.poly.xy = [tup for i, tup in enumerate(self.poly.xy) if i != ind] |
| 117 | + self.poly.xy = [tup |
| 118 | + for i, tup in enumerate(self.poly.xy) |
| 119 | + if i != ind] |
116 | 120 | self.line.set_data(zip(*self.poly.xy))
|
117 | 121 | elif event.key == 'i':
|
118 | 122 | xys = self.poly.get_transform().transform(self.poly.xy)
|
@@ -172,7 +176,6 @@ def motion_notify_callback(self, event):
|
172 | 176 | ax.add_patch(poly)
|
173 | 177 | p = PolygonInteractor(ax, poly)
|
174 | 178 |
|
175 |
| - #ax.add_line(p.line) |
176 | 179 | ax.set_title('Click and drag a point to move it')
|
177 | 180 | ax.set_xlim((-2, 2))
|
178 | 181 | ax.set_ylim((-2, 2))
|
|
0 commit comments