5050import sys
5151import threading
5252import time
53- from typing import TYPE_CHECKING , cast , overload
53+ from typing import IO , TYPE_CHECKING , cast , overload
5454
5555from cycler import cycler # noqa: F401
5656import matplotlib
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 (
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