Skip to content
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 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 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy