@@ -251,7 +251,8 @@ is created every time a mouse is pressed::
251
251
252
252
def __call__(self, event):
253
253
print('click', event)
254
- if event.inaxes!=self.line.axes: return
254
+ if event.inaxes != self.line.axes:
255
+ return
255
256
self.xs.append(event.xdata)
256
257
self.ys.append(event.ydata)
257
258
self.line.set_data(self.xs, self.ys)
@@ -277,17 +278,19 @@ event.ydata)``. In addition to the ``LocationEvent`` attributes, it also has:
277
278
Draggable rectangle exercise
278
279
----------------------------
279
280
280
- Write draggable rectangle class that is initialized with a
281
+ Write a draggable rectangle class that is initialized with a
281
282
`.Rectangle ` instance but will move its ``xy ``
282
- location when dragged. Hint: you will need to store the original
283
- ``xy `` location of the rectangle which is stored as rect.xy and
283
+ location when dragged.
284
+
285
+ Hint: You will need to store the original
286
+ ``xy `` location of the rectangle which is stored as ``rect.xy `` and
284
287
connect to the press, motion and release mouse events. When the mouse
285
288
is pressed, check to see if the click occurs over your rectangle (see
286
289
`.Rectangle.contains `) and if it does, store
287
- the rectangle xy and the location of the mouse click in data coords .
290
+ the rectangle xy and the location of the mouse click in data coordinates .
288
291
In the motion event callback, compute the deltax and deltay of the
289
292
mouse movement, and add those deltas to the origin of the rectangle
290
- you stored. The redraw the figure. On the button release event, just
293
+ you stored, then redraw the figure. On the button release event, just
291
294
reset all the button press data you stored as None.
292
295
293
296
Here is the solution::
0 commit comments