Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FIX: Ensuring both x and y attrs of LocationEvent are int #11530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 1, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions 6 lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,10 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
*x*, *y* in figure coords, 0,0 = bottom, left
"""
Event.__init__(self, name, canvas, guiEvent=guiEvent)
self.x = x # x position - pixels from left of canvas
self.y = y # y position - pixels from right of canvas
# x position - pixels from left of canvas
self.x = int(x) if x is not None else x
# y position - pixels from right of canvas
self.y = int(y) if y is not None else y
self.inaxes = None # the Axes instance if mouse us over axes
self.xdata = None # x coord of mouse in data coords
self.ydata = None # y coord of mouse in data coords
Expand Down
22 changes: 22 additions & 0 deletions 22 lib/matplotlib/tests/test_backend_bases.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from matplotlib.backend_bases import FigureCanvasBase
from matplotlib.backend_bases import RendererBase
from matplotlib.backend_bases import LocationEvent

import matplotlib.pyplot as plt
import matplotlib.transforms as transforms
Expand Down Expand Up @@ -77,3 +78,24 @@ def test_non_gui_warning():
assert len(rec) == 1
assert ('Matplotlib is currently using pdf, which is a non-GUI backend'
in str(rec[0].message))


def test_location_event_position():
# LocationEvent should cast its x and y arguments
# to int unless it is None
fig = plt.figure()
canvas = FigureCanvasBase(fig)
test_positions = [(42, 24), (None, 42), (None, None),
(200, 100.01), (205.75, 2.0)]
for x, y in test_positions:
event = LocationEvent("test_event", canvas, x, y)
if x is None:
assert event.x is None
else:
assert event.x == int(x)
assert isinstance(event.x, int)
if y is None:
assert event.y is None
else:
assert event.y == int(y)
assert isinstance(event.y, int)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.