figure.pyi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. from collections.abc import Callable, Hashable, Iterable
  2. import os
  3. from typing import Any, IO, Literal, TypeVar, overload
  4. import numpy as np
  5. from numpy.typing import ArrayLike
  6. from matplotlib.artist import Artist
  7. from matplotlib.axes import Axes, SubplotBase
  8. from matplotlib.backend_bases import (
  9. FigureCanvasBase,
  10. MouseButton,
  11. MouseEvent,
  12. RendererBase,
  13. )
  14. from matplotlib.colors import Colormap, Normalize
  15. from matplotlib.colorbar import Colorbar
  16. from matplotlib.cm import ScalarMappable
  17. from matplotlib.gridspec import GridSpec, SubplotSpec
  18. from matplotlib.image import _ImageBase, FigureImage
  19. from matplotlib.layout_engine import LayoutEngine
  20. from matplotlib.legend import Legend
  21. from matplotlib.lines import Line2D
  22. from matplotlib.patches import Rectangle, Patch
  23. from matplotlib.text import Text
  24. from matplotlib.transforms import Affine2D, Bbox, BboxBase, Transform
  25. from .typing import ColorType, HashableList
  26. _T = TypeVar("_T")
  27. class SubplotParams:
  28. def __init__(
  29. self,
  30. left: float | None = ...,
  31. bottom: float | None = ...,
  32. right: float | None = ...,
  33. top: float | None = ...,
  34. wspace: float | None = ...,
  35. hspace: float | None = ...,
  36. ) -> None: ...
  37. left: float
  38. right: float
  39. bottom: float
  40. top: float
  41. wspace: float
  42. hspace: float
  43. def update(
  44. self,
  45. left: float | None = ...,
  46. bottom: float | None = ...,
  47. right: float | None = ...,
  48. top: float | None = ...,
  49. wspace: float | None = ...,
  50. hspace: float | None = ...,
  51. ) -> None: ...
  52. class FigureBase(Artist):
  53. artists: list[Artist]
  54. lines: list[Line2D]
  55. patches: list[Patch]
  56. texts: list[Text]
  57. images: list[_ImageBase]
  58. legends: list[Legend]
  59. subfigs: list[SubFigure]
  60. stale: bool
  61. suppressComposite: bool | None
  62. def __init__(self, **kwargs) -> None: ...
  63. def autofmt_xdate(
  64. self,
  65. bottom: float = ...,
  66. rotation: int = ...,
  67. ha: Literal["left", "center", "right"] = ...,
  68. which: Literal["major", "minor", "both"] = ...,
  69. ) -> None: ...
  70. def get_children(self) -> list[Artist]: ...
  71. def contains(self, mouseevent: MouseEvent) -> tuple[bool, dict[Any, Any]]: ...
  72. def suptitle(self, t: str, **kwargs) -> Text: ...
  73. def get_suptitle(self) -> str: ...
  74. def supxlabel(self, t: str, **kwargs) -> Text: ...
  75. def get_supxlabel(self) -> str: ...
  76. def supylabel(self, t: str, **kwargs) -> Text: ...
  77. def get_supylabel(self) -> str: ...
  78. def get_edgecolor(self) -> ColorType: ...
  79. def get_facecolor(self) -> ColorType: ...
  80. def get_frameon(self) -> bool: ...
  81. def set_linewidth(self, linewidth: float) -> None: ...
  82. def get_linewidth(self) -> float: ...
  83. def set_edgecolor(self, color: ColorType) -> None: ...
  84. def set_facecolor(self, color: ColorType) -> None: ...
  85. def set_frameon(self, b: bool) -> None: ...
  86. @property
  87. def frameon(self) -> bool: ...
  88. @frameon.setter
  89. def frameon(self, b: bool) -> None: ...
  90. def add_artist(self, artist: Artist, clip: bool = ...) -> Artist: ...
  91. @overload
  92. def add_axes(self, ax: Axes) -> Axes: ...
  93. @overload
  94. def add_axes(
  95. self,
  96. rect: tuple[float, float, float, float],
  97. projection: None | str = ...,
  98. polar: bool = ...,
  99. **kwargs
  100. ) -> Axes: ...
  101. # TODO: docstring indicates SubplotSpec a valid arg, but none of the listed signatures appear to be that
  102. @overload
  103. def add_subplot(
  104. self, nrows: int, ncols: int, index: int | tuple[int, int], **kwargs
  105. ) -> Axes: ...
  106. @overload
  107. def add_subplot(self, pos: int, **kwargs) -> Axes: ...
  108. @overload
  109. def add_subplot(self, ax: Axes, **kwargs) -> Axes: ...
  110. @overload
  111. def add_subplot(self, ax: SubplotSpec, **kwargs) -> Axes: ...
  112. @overload
  113. def add_subplot(self, **kwargs) -> Axes: ...
  114. @overload
  115. def subplots(
  116. self,
  117. nrows: int = ...,
  118. ncols: int = ...,
  119. *,
  120. sharex: bool | Literal["none", "all", "row", "col"] = ...,
  121. sharey: bool | Literal["none", "all", "row", "col"] = ...,
  122. squeeze: Literal[False],
  123. width_ratios: ArrayLike | None = ...,
  124. height_ratios: ArrayLike | None = ...,
  125. subplot_kw: dict[str, Any] | None = ...,
  126. gridspec_kw: dict[str, Any] | None = ...
  127. ) -> np.ndarray: ...
  128. @overload
  129. def subplots(
  130. self,
  131. nrows: int = ...,
  132. ncols: int = ...,
  133. *,
  134. sharex: bool | Literal["none", "all", "row", "col"] = ...,
  135. sharey: bool | Literal["none", "all", "row", "col"] = ...,
  136. squeeze: bool = ...,
  137. width_ratios: ArrayLike | None = ...,
  138. height_ratios: ArrayLike | None = ...,
  139. subplot_kw: dict[str, Any] | None = ...,
  140. gridspec_kw: dict[str, Any] | None = ...
  141. ) -> np.ndarray | SubplotBase | Axes: ...
  142. def delaxes(self, ax: Axes) -> None: ...
  143. def clear(self, keep_observers: bool = ...) -> None: ...
  144. def clf(self, keep_observers: bool = ...) -> None: ...
  145. @overload
  146. def legend(self) -> Legend: ...
  147. @overload
  148. def legend(self, handles: Iterable[Artist], labels: Iterable[str], **kwargs) -> Legend: ...
  149. @overload
  150. def legend(self, *, handles: Iterable[Artist], **kwargs) -> Legend: ...
  151. @overload
  152. def legend(self, labels: Iterable[str], **kwargs) -> Legend: ...
  153. @overload
  154. def legend(self, **kwargs) -> Legend: ...
  155. def text(
  156. self,
  157. x: float,
  158. y: float,
  159. s: str,
  160. fontdict: dict[str, Any] | None = ...,
  161. **kwargs
  162. ) -> Text: ...
  163. def colorbar(
  164. self,
  165. mappable: ScalarMappable,
  166. cax: Axes | None = ...,
  167. ax: Axes | Iterable[Axes] | None = ...,
  168. use_gridspec: bool = ...,
  169. **kwargs
  170. ) -> Colorbar: ...
  171. def subplots_adjust(
  172. self,
  173. left: float | None = ...,
  174. bottom: float | None = ...,
  175. right: float | None = ...,
  176. top: float | None = ...,
  177. wspace: float | None = ...,
  178. hspace: float | None = ...,
  179. ) -> None: ...
  180. def align_xlabels(self, axs: Iterable[Axes] | None = ...) -> None: ...
  181. def align_ylabels(self, axs: Iterable[Axes] | None = ...) -> None: ...
  182. def align_labels(self, axs: Iterable[Axes] | None = ...) -> None: ...
  183. def add_gridspec(self, nrows: int = ..., ncols: int = ..., **kwargs) -> GridSpec: ...
  184. @overload
  185. def subfigures(
  186. self,
  187. nrows: int = ...,
  188. ncols: int = ...,
  189. squeeze: Literal[False] = ...,
  190. wspace: float | None = ...,
  191. hspace: float | None = ...,
  192. width_ratios: ArrayLike | None = ...,
  193. height_ratios: ArrayLike | None = ...,
  194. **kwargs
  195. ) -> np.ndarray: ...
  196. @overload
  197. def subfigures(
  198. self,
  199. nrows: int = ...,
  200. ncols: int = ...,
  201. squeeze: Literal[True] = ...,
  202. wspace: float | None = ...,
  203. hspace: float | None = ...,
  204. width_ratios: ArrayLike | None = ...,
  205. height_ratios: ArrayLike | None = ...,
  206. **kwargs
  207. ) -> np.ndarray | SubFigure: ...
  208. def add_subfigure(self, subplotspec: SubplotSpec, **kwargs) -> SubFigure: ...
  209. def sca(self, a: Axes) -> Axes: ...
  210. def gca(self) -> Axes: ...
  211. def _gci(self) -> ScalarMappable | None: ...
  212. def _process_projection_requirements(
  213. self, *, axes_class=None, polar=False, projection=None, **kwargs
  214. ) -> tuple[type[Axes], dict[str, Any]]: ...
  215. def get_default_bbox_extra_artists(self) -> list[Artist]: ...
  216. def get_tightbbox(
  217. self,
  218. renderer: RendererBase | None = ...,
  219. *,
  220. bbox_extra_artists: Iterable[Artist] | None = ...,
  221. ) -> Bbox: ...
  222. @overload
  223. def subplot_mosaic(
  224. self,
  225. mosaic: str,
  226. *,
  227. sharex: bool = ...,
  228. sharey: bool = ...,
  229. width_ratios: ArrayLike | None = ...,
  230. height_ratios: ArrayLike | None = ...,
  231. empty_sentinel: str = ...,
  232. subplot_kw: dict[str, Any] | None = ...,
  233. per_subplot_kw: dict[str | tuple[str, ...], dict[str, Any]] | None = ...,
  234. gridspec_kw: dict[str, Any] | None = ...,
  235. ) -> dict[str, Axes]: ...
  236. @overload
  237. def subplot_mosaic(
  238. self,
  239. mosaic: list[HashableList[_T]],
  240. *,
  241. sharex: bool = ...,
  242. sharey: bool = ...,
  243. width_ratios: ArrayLike | None = ...,
  244. height_ratios: ArrayLike | None = ...,
  245. empty_sentinel: _T = ...,
  246. subplot_kw: dict[str, Any] | None = ...,
  247. per_subplot_kw: dict[_T | tuple[_T, ...], dict[str, Any]] | None = ...,
  248. gridspec_kw: dict[str, Any] | None = ...,
  249. ) -> dict[_T, Axes]: ...
  250. @overload
  251. def subplot_mosaic(
  252. self,
  253. mosaic: list[HashableList[Hashable]],
  254. *,
  255. sharex: bool = ...,
  256. sharey: bool = ...,
  257. width_ratios: ArrayLike | None = ...,
  258. height_ratios: ArrayLike | None = ...,
  259. empty_sentinel: Any = ...,
  260. subplot_kw: dict[str, Any] | None = ...,
  261. per_subplot_kw: dict[Hashable | tuple[Hashable, ...], dict[str, Any]] | None = ...,
  262. gridspec_kw: dict[str, Any] | None = ...,
  263. ) -> dict[Hashable, Axes]: ...
  264. class SubFigure(FigureBase):
  265. figure: Figure
  266. subplotpars: SubplotParams
  267. dpi_scale_trans: Affine2D
  268. canvas: FigureCanvasBase
  269. transFigure: Transform
  270. bbox_relative: Bbox
  271. figbbox: BboxBase
  272. bbox: BboxBase
  273. transSubfigure: Transform
  274. patch: Rectangle
  275. def __init__(
  276. self,
  277. parent: Figure | SubFigure,
  278. subplotspec: SubplotSpec,
  279. *,
  280. facecolor: ColorType | None = ...,
  281. edgecolor: ColorType | None = ...,
  282. linewidth: float = ...,
  283. frameon: bool | None = ...,
  284. **kwargs
  285. ) -> None: ...
  286. @property
  287. def dpi(self) -> float: ...
  288. @dpi.setter
  289. def dpi(self, value: float) -> None: ...
  290. def get_dpi(self) -> float: ...
  291. def set_dpi(self, val) -> None: ...
  292. def get_constrained_layout(self) -> bool: ...
  293. def get_constrained_layout_pads(
  294. self, relative: bool = ...
  295. ) -> tuple[float, float, float, float]: ...
  296. def get_layout_engine(self) -> LayoutEngine: ...
  297. @property # type: ignore[misc]
  298. def axes(self) -> list[Axes]: ... # type: ignore[override]
  299. def get_axes(self) -> list[Axes]: ...
  300. class Figure(FigureBase):
  301. figure: Figure
  302. bbox_inches: Bbox
  303. dpi_scale_trans: Affine2D
  304. bbox: BboxBase
  305. figbbox: BboxBase
  306. transFigure: Transform
  307. transSubfigure: Transform
  308. patch: Rectangle
  309. subplotpars: SubplotParams
  310. def __init__(
  311. self,
  312. figsize: tuple[float, float] | None = ...,
  313. dpi: float | None = ...,
  314. *,
  315. facecolor: ColorType | None = ...,
  316. edgecolor: ColorType | None = ...,
  317. linewidth: float = ...,
  318. frameon: bool | None = ...,
  319. subplotpars: SubplotParams | None = ...,
  320. tight_layout: bool | dict[str, Any] | None = ...,
  321. constrained_layout: bool | dict[str, Any] | None = ...,
  322. layout: Literal["constrained", "compressed", "tight"]
  323. | LayoutEngine
  324. | None = ...,
  325. **kwargs
  326. ) -> None: ...
  327. def pick(self, mouseevent: MouseEvent) -> None: ...
  328. def set_layout_engine(
  329. self,
  330. layout: Literal["constrained", "compressed", "tight", "none"]
  331. | LayoutEngine
  332. | None = ...,
  333. **kwargs
  334. ) -> None: ...
  335. def get_layout_engine(self) -> LayoutEngine | None: ...
  336. def _repr_html_(self) -> str | None: ...
  337. def show(self, warn: bool = ...) -> None: ...
  338. @property # type: ignore[misc]
  339. def axes(self) -> list[Axes]: ... # type: ignore[override]
  340. def get_axes(self) -> list[Axes]: ...
  341. @property
  342. def dpi(self) -> float: ...
  343. @dpi.setter
  344. def dpi(self, dpi: float) -> None: ...
  345. def get_tight_layout(self) -> bool: ...
  346. def get_constrained_layout_pads(
  347. self, relative: bool = ...
  348. ) -> tuple[float, float, float, float]: ...
  349. def get_constrained_layout(self) -> bool: ...
  350. canvas: FigureCanvasBase
  351. def set_canvas(self, canvas: FigureCanvasBase) -> None: ...
  352. def figimage(
  353. self,
  354. X: ArrayLike,
  355. xo: int = ...,
  356. yo: int = ...,
  357. alpha: float | None = ...,
  358. norm: str | Normalize | None = ...,
  359. cmap: str | Colormap | None = ...,
  360. vmin: float | None = ...,
  361. vmax: float | None = ...,
  362. origin: Literal["upper", "lower"] | None = ...,
  363. resize: bool = ...,
  364. **kwargs
  365. ) -> FigureImage: ...
  366. def set_size_inches(
  367. self, w: float | tuple[float, float], h: float | None = ..., forward: bool = ...
  368. ) -> None: ...
  369. def get_size_inches(self) -> np.ndarray: ...
  370. def get_figwidth(self) -> float: ...
  371. def get_figheight(self) -> float: ...
  372. def get_dpi(self) -> float: ...
  373. def set_dpi(self, val: float) -> None: ...
  374. def set_figwidth(self, val: float, forward: bool = ...) -> None: ...
  375. def set_figheight(self, val: float, forward: bool = ...) -> None: ...
  376. def clear(self, keep_observers: bool = ...) -> None: ...
  377. def draw_without_rendering(self) -> None: ...
  378. def draw_artist(self, a: Artist) -> None: ...
  379. def add_axobserver(self, func: Callable[[Figure], Any]) -> None: ...
  380. def savefig(
  381. self,
  382. fname: str | os.PathLike | IO,
  383. *,
  384. transparent: bool | None = ...,
  385. **kwargs
  386. ) -> None: ...
  387. def ginput(
  388. self,
  389. n: int = ...,
  390. timeout: float = ...,
  391. show_clicks: bool = ...,
  392. mouse_add: MouseButton = ...,
  393. mouse_pop: MouseButton = ...,
  394. mouse_stop: MouseButton = ...,
  395. ) -> list[tuple[int, int]]: ...
  396. def waitforbuttonpress(self, timeout: float = ...) -> None | bool: ...
  397. def tight_layout(
  398. self,
  399. *,
  400. pad: float = ...,
  401. h_pad: float | None = ...,
  402. w_pad: float | None = ...,
  403. rect: tuple[float, float, float, float] | None = ...
  404. ) -> None: ...
  405. def figaspect(arg: float | ArrayLike) -> tuple[float, float]: ...