@@ -34,8 +34,8 @@ was pressed::
34
34
ax.plot(np.random.rand(10))
35
35
36
36
def onclick(event):
37
- print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
38
- event.button, event.x, event.y, event.xdata, event.ydata)
37
+ print( 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
38
+ ( event.button, event.x, event.y, event.xdata, event.ydata) )
39
39
40
40
cid = fig.canvas.mpl_connect('button_press_event', onclick)
41
41
@@ -128,7 +128,7 @@ is created every time a mouse is pressed::
128
128
self.cid = line.figure.canvas.mpl_connect('button_press_event', self)
129
129
130
130
def __call__(self, event):
131
- print 'click', event
131
+ print( 'click', event)
132
132
if event.inaxes!=self.line.axes: return
133
133
self.xs.append(event.xdata)
134
134
self.ys.append(event.ydata)
@@ -196,7 +196,7 @@ Here is the solution::
196
196
197
197
contains, attrd = self.rect.contains(event)
198
198
if not contains: return
199
- print 'event contains', self.rect.xy
199
+ print( 'event contains', self.rect.xy)
200
200
x0, y0 = self.rect.xy
201
201
self.press = x0, y0, event.xdata, event.ydata
202
202
@@ -207,7 +207,8 @@ Here is the solution::
207
207
x0, y0, xpress, ypress = self.press
208
208
dx = event.xdata - xpress
209
209
dy = event.ydata - ypress
210
- #print 'x0=%f, xpress=%f, event.xdata=%f, dx=%f, x0+dx=%f'%(x0, xpress, event.xdata, dx, x0+dx)
210
+ #print('x0=%f, xpress=%f, event.xdata=%f, dx=%f, x0+dx=%f' %
211
+ # (x0, xpress, event.xdata, dx, x0+dx))
211
212
self.rect.set_x(x0+dx)
212
213
self.rect.set_y(y0+dy)
213
214
@@ -271,7 +272,7 @@ Extra credit solution::
271
272
if DraggableRectangle.lock is not None: return
272
273
contains, attrd = self.rect.contains(event)
273
274
if not contains: return
274
- print 'event contains', self.rect.xy
275
+ print( 'event contains', self.rect.xy)
275
276
x0, y0 = self.rect.xy
276
277
self.press = x0, y0, event.xdata, event.ydata
277
278
DraggableRectangle.lock = self
@@ -361,22 +362,22 @@ background that the mouse is over::
361
362
import matplotlib.pyplot as plt
362
363
363
364
def enter_axes(event):
364
- print 'enter_axes', event.inaxes
365
+ print( 'enter_axes', event.inaxes)
365
366
event.inaxes.patch.set_facecolor('yellow')
366
367
event.canvas.draw()
367
368
368
369
def leave_axes(event):
369
- print 'leave_axes', event.inaxes
370
+ print( 'leave_axes', event.inaxes)
370
371
event.inaxes.patch.set_facecolor('white')
371
372
event.canvas.draw()
372
373
373
374
def enter_figure(event):
374
- print 'enter_figure', event.canvas.figure
375
+ print( 'enter_figure', event.canvas.figure)
375
376
event.canvas.figure.patch.set_facecolor('red')
376
377
event.canvas.draw()
377
378
378
379
def leave_figure(event):
379
- print 'leave_figure', event.canvas.figure
380
+ print( 'leave_figure', event.canvas.figure)
380
381
event.canvas.figure.patch.set_facecolor('grey')
381
382
event.canvas.draw()
382
383
@@ -403,7 +404,6 @@ background that the mouse is over::
403
404
plt.show()
404
405
405
406
406
-
407
407
.. _object-picking :
408
408
409
409
Object picking
@@ -503,7 +503,8 @@ properties of the line. Here is the code::
503
503
xdata = thisline.get_xdata()
504
504
ydata = thisline.get_ydata()
505
505
ind = event.ind
506
- print 'onpick points:', zip(xdata[ind], ydata[ind])
506
+ points = tuple(zip(xdata[ind], ydata[ind]))
507
+ print('onpick points:', points)
507
508
508
509
fig.canvas.mpl_connect('pick_event', onpick)
509
510
0 commit comments