X Tutup
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions doc/users/event_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ was pressed::
ax.plot(np.random.rand(10))

def onclick(event):
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
(event.button, event.x, event.y, event.xdata, event.ydata))

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

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

def __call__(self, event):
print 'click', event
print('click', event)
if event.inaxes!=self.line.axes: return
self.xs.append(event.xdata)
self.ys.append(event.ydata)
Expand Down Expand Up @@ -196,7 +196,7 @@ Here is the solution::

contains, attrd = self.rect.contains(event)
if not contains: return
print 'event contains', self.rect.xy
print('event contains', self.rect.xy)
x0, y0 = self.rect.xy
self.press = x0, y0, event.xdata, event.ydata

Expand All @@ -207,7 +207,8 @@ Here is the solution::
x0, y0, xpress, ypress = self.press
dx = event.xdata - xpress
dy = event.ydata - ypress
#print 'x0=%f, xpress=%f, event.xdata=%f, dx=%f, x0+dx=%f'%(x0, xpress, event.xdata, dx, x0+dx)
#print('x0=%f, xpress=%f, event.xdata=%f, dx=%f, x0+dx=%f' %
# (x0, xpress, event.xdata, dx, x0+dx))
self.rect.set_x(x0+dx)
self.rect.set_y(y0+dy)

Expand Down Expand Up @@ -271,7 +272,7 @@ Extra credit solution::
if DraggableRectangle.lock is not None: return
contains, attrd = self.rect.contains(event)
if not contains: return
print 'event contains', self.rect.xy
print('event contains', self.rect.xy)
x0, y0 = self.rect.xy
self.press = x0, y0, event.xdata, event.ydata
DraggableRectangle.lock = self
Expand Down Expand Up @@ -361,22 +362,22 @@ background that the mouse is over::
import matplotlib.pyplot as plt

def enter_axes(event):
print 'enter_axes', event.inaxes
print('enter_axes', event.inaxes)
event.inaxes.patch.set_facecolor('yellow')
event.canvas.draw()

def leave_axes(event):
print 'leave_axes', event.inaxes
print('leave_axes', event.inaxes)
event.inaxes.patch.set_facecolor('white')
event.canvas.draw()

def enter_figure(event):
print 'enter_figure', event.canvas.figure
print('enter_figure', event.canvas.figure)
event.canvas.figure.patch.set_facecolor('red')
event.canvas.draw()

def leave_figure(event):
print 'leave_figure', event.canvas.figure
print('leave_figure', event.canvas.figure)
event.canvas.figure.patch.set_facecolor('grey')
event.canvas.draw()

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



.. _object-picking:

Object picking
Expand Down Expand Up @@ -503,7 +503,8 @@ properties of the line. Here is the code::
xdata = thisline.get_xdata()
ydata = thisline.get_ydata()
ind = event.ind
print 'onpick points:', zip(xdata[ind], ydata[ind])
points = tuple(zip(xdata[ind], ydata[ind]))
print('onpick points:', points)

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

Expand Down
X Tutup