Skip to content

Commit cf1a70c

Browse files
committed
Minor pyplot error fixed
1 parent 7dc5eaa commit cf1a70c

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

lib/matplotlib/pyplot.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import sys
5151
import threading
5252
import time
53-
from typing import TYPE_CHECKING, cast, overload
53+
from typing import IO, TYPE_CHECKING, cast, overload
5454

5555
from cycler import cycler # noqa: F401
5656
import matplotlib
@@ -100,7 +100,14 @@
100100
import matplotlib.backend_bases
101101
from matplotlib.axis import Tick
102102
from matplotlib.axes._base import _AxesBase
103-
from matplotlib.backend_bases import Event
103+
from matplotlib.backend_bases import (
104+
CloseEvent,
105+
DrawEvent,
106+
KeyEvent,
107+
MouseEvent,
108+
PickEvent,
109+
ResizeEvent,
110+
)
104111
from matplotlib.cm import ScalarMappable
105112
from matplotlib.contour import ContourSet, QuadContourSet
106113
from matplotlib.collections import (
@@ -126,11 +133,18 @@
126133
from matplotlib.quiver import Barbs, Quiver, QuiverKey
127134
from matplotlib.scale import ScaleBase
128135
from matplotlib.typing import (
136+
CloseEventType,
129137
ColorType,
130138
CoordsType,
139+
DrawEventType,
131140
HashableList,
141+
KeyEventType,
132142
LineStyleType,
133143
MarkerType,
144+
MouseEventType,
145+
PickEventType,
146+
ResizeEventType,
147+
LogLevel
134148
)
135149
from matplotlib.widgets import SubplotTool
136150

@@ -338,8 +352,8 @@ def uninstall_repl_displayhook() -> None:
338352

339353
# Ensure this appears in the pyplot docs.
340354
@_copy_docstring_and_deprecators(matplotlib.set_loglevel)
341-
def set_loglevel(*args, **kwargs) -> None:
342-
return matplotlib.set_loglevel(*args, **kwargs)
355+
def set_loglevel(level: LogLevel) -> None:
356+
return matplotlib.set_loglevel(level)
343357

344358

345359
@_copy_docstring_and_deprecators(Artist.findobj)
@@ -1175,8 +1189,32 @@ def get_current_fig_manager() -> FigureManagerBase | None:
11751189
return gcf().canvas.manager
11761190

11771191

1192+
@overload
1193+
def connect(s: MouseEventType, func: Callable[[MouseEvent], Any]) -> int: ...
1194+
1195+
1196+
@overload
1197+
def connect(s: KeyEventType, func: Callable[[KeyEvent], Any]) -> int: ...
1198+
1199+
1200+
@overload
1201+
def connect(s: PickEventType, func: Callable[[PickEvent], Any]) -> int: ...
1202+
1203+
1204+
@overload
1205+
def connect(s: ResizeEventType, func: Callable[[ResizeEvent], Any]) -> int: ...
1206+
1207+
1208+
@overload
1209+
def connect(s: CloseEventType, func: Callable[[CloseEvent], Any]) -> int: ...
1210+
1211+
1212+
@overload
1213+
def connect(s: DrawEventType, func: Callable[[DrawEvent], Any]) -> int: ...
1214+
1215+
11781216
@_copy_docstring_and_deprecators(FigureCanvasBase.mpl_connect)
1179-
def connect(s: str, func: Callable[[Event], Any]) -> int:
1217+
def connect(s, func) -> int:
11801218
return gcf().canvas.mpl_connect(s, func)
11811219

11821220

@@ -1259,11 +1297,11 @@ def draw() -> None:
12591297

12601298

12611299
@_copy_docstring_and_deprecators(Figure.savefig)
1262-
def savefig(*args, **kwargs) -> None:
1300+
def savefig(fname: str | os.PathLike | IO, **kwargs) -> None:
12631301
fig = gcf()
12641302
# savefig default implementation has no return, so mypy is unhappy
12651303
# presumably this is here because subclasses can return?
1266-
res = fig.savefig(*args, **kwargs) # type: ignore[func-returns-value]
1304+
res = fig.savefig(fname, **kwargs) # type: ignore[func-returns-value]
12671305
fig.canvas.draw_idle() # Need this if 'transparent=True', to reset colors.
12681306
return res
12691307

@@ -4718,4 +4756,4 @@ def nipy_spectral() -> None:
47184756
This changes the default colormap as well as the colormap of the current
47194757
image if there is one. See ``help(colormaps)`` for more information.
47204758
"""
4721-
set_cmap("nipy_spectral")
4759+
set_cmap("nipy_spectral")

0 commit comments

Comments
 (0)
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