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

Commit 1285e59

Browse filesBrowse files
authored
Merge pull request #11447 from timhoffm/improper-class-variables
Do not use class attributes as defaults for instance attributes
2 parents 5a7638e + f0bf8d0 commit 1285e59
Copy full SHA for 1285e59

File tree

Expand file treeCollapse file tree

1 file changed

+20
-34
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-34
lines changed

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+20-34Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ def __init__(self, name, canvas, guiEvent=None):
13321332

13331333
class LocationEvent(Event):
13341334
"""
1335-
An event that has a screen location
1335+
An event that has a screen location.
13361336
13371337
The following additional attributes are defined and shown with
13381338
their default values.
@@ -1356,28 +1356,23 @@ class LocationEvent(Event):
13561356
13571357
ydata : scalar
13581358
y coord of mouse in data coords
1359-
13601359
"""
1361-
x = None # x position - pixels from left of canvas
1362-
y = None # y position - pixels from right of canvas
1363-
inaxes = None # the Axes instance if mouse us over axes
1364-
xdata = None # x coord of mouse in data coords
1365-
ydata = None # y coord of mouse in data coords
13661360

1367-
# the last event that was triggered before this one
1368-
lastevent = None
1361+
lastevent = None # the last event that was triggered before this one
13691362

13701363
def __init__(self, name, canvas, x, y, guiEvent=None):
13711364
"""
13721365
*x*, *y* in figure coords, 0,0 = bottom, left
13731366
"""
13741367
Event.__init__(self, name, canvas, guiEvent=guiEvent)
1375-
self.x = x
1376-
self.y = y
1368+
self.x = x # x position - pixels from left of canvas
1369+
self.y = y # y position - pixels from right of canvas
1370+
self.inaxes = None # the Axes instance if mouse us over axes
1371+
self.xdata = None # x coord of mouse in data coords
1372+
self.ydata = None # y coord of mouse in data coords
13771373

13781374
if x is None or y is None:
13791375
# cannot check if event was in axes if no x,y info
1380-
self.inaxes = None
13811376
self._update_enter_leave()
13821377
return
13831378

@@ -1394,13 +1389,10 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
13941389
trans = self.inaxes.transData.inverted()
13951390
xdata, ydata = trans.transform_point((x, y))
13961391
except ValueError:
1397-
self.xdata = None
1398-
self.ydata = None
1392+
pass
13991393
else:
14001394
self.xdata = xdata
14011395
self.ydata = ydata
1402-
else:
1403-
self.inaxes = None
14041396

14051397
self._update_enter_leave()
14061398

@@ -1443,18 +1435,21 @@ class MouseEvent(LocationEvent):
14431435
14441436
Attributes
14451437
----------
1446-
button : None, scalar, or str
1447-
button pressed None, 1, 2, 3, 'up', 'down' (up and down are used
1448-
for scroll events). Note that in the nbagg backend, both the
1449-
middle and right clicks return 3 since right clicking will bring
1450-
up the context menu in some browsers.
1438+
button : {None, 1, 2, 3, 'up', 'down'}
1439+
The button pressed. 'up' and 'down' are used for scroll events.
1440+
Note that in the nbagg backend, both the middle and right clicks
1441+
return 3 since right clicking will bring up the context menu in
1442+
some browsers.
14511443
1452-
key : None, or str
1453-
the key depressed when the mouse event triggered (see
1454-
:class:`KeyEvent`)
1444+
key : None or str
1445+
The key pressed when the mouse event triggered, e.g. 'shift'.
1446+
See `KeyEvent`.
14551447
14561448
step : scalar
1457-
number of scroll steps (positive for 'up', negative for 'down')
1449+
The Number of scroll steps (positive for 'up', negative for 'down').
1450+
1451+
dblclick : bool
1452+
*True* if the event is a double-click.
14581453
14591454
Examples
14601455
--------
@@ -1464,16 +1459,7 @@ def on_press(event):
14641459
print('you pressed', event.button, event.xdata, event.ydata)
14651460
14661461
cid = fig.canvas.mpl_connect('button_press_event', on_press)
1467-
14681462
"""
1469-
x = None # x position - pixels from left of canvas
1470-
y = None # y position - pixels from right of canvas
1471-
button = None # button pressed None, 1, 2, 3
1472-
dblclick = None # whether or not the event is the result of a double click
1473-
inaxes = None # the Axes instance if mouse us over axes
1474-
xdata = None # x coord of mouse in data coords
1475-
ydata = None # y coord of mouse in data coords
1476-
step = None # scroll steps for scroll events
14771463

14781464
def __init__(self, name, canvas, x, y, button=None, key=None,
14791465
step=0, dblclick=False, guiEvent=None):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.