10000 Merge pull request #6354 from pganssle/event_doc_py3 · blink1073/matplotlib@3b8c094 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b8c094

Browse files
committed
Merge pull request matplotlib#6354 from pganssle/event_doc_py3
DOC: Update events handling documentation to work with Python 3.
2 parents c227b14 + e50038d commit 3b8c094

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

doc/users/event_handling.rst

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ was pressed::
3434
ax.plot(np.random.rand(10))
3535

3636
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))
3939

4040
cid = fig.canvas.mpl_connect('button_press_event', onclick)
4141

@@ -128,7 +128,7 @@ is created every time a mouse is pressed::
128128
self.cid = line.figure.canvas.mpl_connect('button_press_event', self)
129129

130130
def __call__(self, event):
131-
print 'click', event
131+
print('click', event)
132132
if event.inaxes!=self.line.axes: return
133133
self.xs.append(event.xdata)
134134
self.ys.append(event.ydata)
@@ -196,7 +196,7 @@ Here is the solution::
196196

197197
contains, attrd = self.rect.contains(event)
198198
if not contains: return
199-
print 'event contains', self.rect.xy
199+
print('event contains', self.rect.xy)
200200
x0, y0 = self.rect.xy
201201
self.press = x0, y0, event.xdata, event.ydata
202202

@@ -207,7 +207,8 @@ Here is the solution::
207207
x0, y0, xpress, ypress = self.press
208208
dx = event.xdata - xpress
209209
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))
211212
self.rect.set_x(x0+dx)
212213
self.rect.set_y(y0+dy)
213214

@@ -271,7 +272,7 @@ Extra credit solution::
271272
if DraggableRectangle.lock is not None: return
272273
contains, attrd = self.rect.contains(event)
273274
if not contains: return
274-
print 'event contains', self.rect.xy
275+
print('event contains', self.rect.xy)
275276
x0, y0 = self.rect.xy
276277
self.press = x0, y0, event.xdata, event.ydata
277278
DraggableRectangle.lock = self
@@ -361,22 +362,22 @@ background that the mouse is over::
361362
import matplotlib.pyplot as plt
362363

363364
def enter_axes(event):
364-
print 'enter_axes', event.inaxes
365+
print('enter_axes', event.inaxes)
365366
event.inaxes.patch.set_facecolor('yellow')
366367
event.canvas.draw()
367368

368369
def leave_axes(event):
369-
print 'leave_axes', event.inaxes
370+
print('leave_axes', event.inaxes)
370371
event.inaxes.patch.set_facecolor('white')
371372
event.canvas.draw()
372373

373374
def enter_figure(event):
374-
print 'enter_figure', event.canvas.figure
375+
print('enter_figure', event.canvas.figure)
375376
event.canvas.figure.patch.set_facecolor('red')
376377
event.canvas.draw()
377378

378379
def leave_figure(event):
379-
print 'leave_figure', event.canvas.figure
380+
print('leave_figure', event.canvas.figure)
380381
event.canvas.figure.patch.set_facecolor('grey')
381382
event.canvas.draw()
382383

@@ -403,7 +404,6 @@ background that the mouse is over::
403404
plt.show()
404405

405406

406-
407407
.. _object-picking:
408408

409409
Object picking
@@ -503,7 +503,8 @@ properties of the line. Here is the code::
503503
xdata = thisline.get_xdata()
504504
ydata = thisline.get_ydata()
505505
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)
507508

508509
fig.canvas.mpl_connect('pick_event', onpick)
509510

0 commit comments

Comments
 (0)
0