Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite3e7792

Browse files
authored
Merge pull request#16277 from anntzer/mousebuttondocs
Prefer using MouseButton to numeric values in docs and defaults.
2 parents31ba9ff +786892b commite3e7792

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

‎lib/matplotlib/blocking_input.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
fromnumbersimportIntegral
2525

2626
frommatplotlibimportcbook
27+
frommatplotlib.backend_basesimportMouseButton
2728
importmatplotlib.linesasmlines
2829

2930
_log=logging.getLogger(__name__)
@@ -103,15 +104,18 @@ class BlockingMouseInput(BlockingInput):
103104
Callable for retrieving mouse clicks in a blocking way.
104105
105106
This class will also retrieve keypresses and map them to mouse clicks:
106-
delete and backspace arelike mouse button 3, enter is likemouse button 2
107-
and all others are likemouse button 1.
107+
delete and backspace area right click, enter is likea middle click,
108+
and all others are likea left click.
108109
"""
109110

110-
button_add=1
111-
button_pop=3
112-
button_stop=2
111+
button_add=MouseButton.LEFT
112+
button_pop=MouseButton.RIGHT
113+
button_stop=MouseButton.MIDDLE
113114

114-
def__init__(self,fig,mouse_add=1,mouse_pop=3,mouse_stop=2):
115+
def__init__(self,fig,
116+
mouse_add=MouseButton.LEFT,
117+
mouse_pop=MouseButton.RIGHT,
118+
mouse_stop=MouseButton.MIDDLE):
115119
BlockingInput.__init__(self,fig=fig,
116120
eventslist=('button_press_event',
117121
'key_press_event'))

‎lib/matplotlib/figure.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
importmatplotlib.artistasmartist
2323
frommatplotlib.artistimportArtist,allow_rasterization
24-
frommatplotlib.backend_basesimportFigureCanvasBase,NonGuiException
24+
frommatplotlib.backend_basesimport (
25+
FigureCanvasBase,NonGuiException,MouseButton)
2526
importmatplotlib.cbookascbook
2627
importmatplotlib.colorbarascbar
2728
importmatplotlib.imageasmimage
@@ -2233,8 +2234,10 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
22332234
ax.set_position(ax.figbox)
22342235
self.stale=True
22352236

2236-
defginput(self,n=1,timeout=30,show_clicks=True,mouse_add=1,
2237-
mouse_pop=3,mouse_stop=2):
2237+
defginput(self,n=1,timeout=30,show_clicks=True,
2238+
mouse_add=MouseButton.LEFT,
2239+
mouse_pop=MouseButton.RIGHT,
2240+
mouse_stop=MouseButton.MIDDLE):
22382241
"""
22392242
Blocking call to interact with a figure.
22402243
@@ -2248,13 +2251,7 @@ def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1,
22482251
- Stop the interaction and return the points added so far.
22492252
22502253
The actions are assigned to mouse buttons via the arguments
2251-
*mouse_add*, *mouse_pop* and *mouse_stop*. Mouse buttons are defined
2252-
by the numbers:
2253-
2254-
- 1: left mouse button
2255-
- 2: middle mouse button
2256-
- 3: right mouse button
2257-
- None: no mouse button
2254+
*mouse_add*, *mouse_pop* and *mouse_stop*.
22582255
22592256
Parameters
22602257
----------
@@ -2266,11 +2263,11 @@ def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1,
22662263
will never timeout.
22672264
show_clicks : bool, default: True
22682265
If True, show a red cross at the location of each click.
2269-
mouse_add :{1, 2, 3,None}, default:1 (left click)
2266+
mouse_add :`.MouseButton` orNone, default:`.MouseButton.LEFT`
22702267
Mouse button used to add points.
2271-
mouse_pop :{1, 2, 3,None}, default:3 (right click)
2268+
mouse_pop :`.MouseButton` orNone, default:`.MouseButton.RIGHT`
22722269
Mouse button used to remove the most recently added point.
2273-
mouse_stop :{1, 2, 3,None}, default:2 (middle click)
2270+
mouse_stop :`.MouseButton` orNone, default:`.MouseButton.MIDDLE`
22742271
Mouse button used to stop input.
22752272
22762273
Returns

‎lib/matplotlib/pyplot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
frommatplotlibimportcbook
3737
frommatplotlib.cbookimportdedent,deprecated,silent_list,warn_deprecated
3838
frommatplotlibimportdocstring
39-
frommatplotlib.backend_basesimportFigureCanvasBase
39+
frommatplotlib.backend_basesimportFigureCanvasBase,MouseButton
4040
frommatplotlib.figureimportFigure,figaspect
4141
frommatplotlib.gridspecimportGridSpec
4242
frommatplotlibimportrcParams,rcParamsDefault,get_backend,rcParamsOrig
@@ -2132,8 +2132,9 @@ def gci():
21322132
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
21332133
@docstring.copy(Figure.ginput)
21342134
defginput(
2135-
n=1,timeout=30,show_clicks=True,mouse_add=1,mouse_pop=3,
2136-
mouse_stop=2):
2135+
n=1,timeout=30,show_clicks=True,
2136+
mouse_add=MouseButton.LEFT,mouse_pop=MouseButton.RIGHT,
2137+
mouse_stop=MouseButton.MIDDLE):
21372138
returngcf().ginput(
21382139
n=n,timeout=timeout,show_clicks=show_clicks,
21392140
mouse_add=mouse_add,mouse_pop=mouse_pop,

‎lib/matplotlib/widgets.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,11 +2008,6 @@ def __init__(self, ax, onselect, drawtype='box',
20082008
*button* is the `.MouseButton` or list of `.MouseButton`\s used for
20092009
rectangle selection. Default is *None*, which means any button.
20102010
2011-
Note, typically:
2012-
1 = left mouse button
2013-
2 = center mouse button (scroll wheel)
2014-
3 = right mouse button
2015-
20162011
*interactive* will draw a set of handles and allow you interact
20172012
with the widget after it is drawn.
20182013

‎tools/boilerplate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# runtime with the proper signatures, a static pyplot.py is simpler for static
1414
# analysis tools to parse.
1515

16+
fromenumimportEnum
1617
importinspect
1718
frominspectimportParameter
1819
frompathlibimportPath
@@ -84,6 +85,9 @@ def __init__(self, value):
8485
self._repr="np.mean"
8586
elifvalueiscbook.deprecation._deprecated_parameter:
8687
self._repr="cbook.deprecation._deprecated_parameter"
88+
elifisinstance(value,Enum):
89+
# Enum str is Class.Name whereas their repr is <Class.Name: value>.
90+
self._repr=str(value)
8791
else:
8892
self._repr=repr(value)
8993

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp