figure.pyi 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. from collections.abc import Callable, Hashable, Iterable, Sequence
  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
  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.colorizer import ColorizingArtist, Colorizer
  17. from matplotlib.cm import ScalarMappable
  18. from matplotlib.gridspec import GridSpec, SubplotSpec, SubplotParams as SubplotParams
  19. from matplotlib.image import _ImageBase, FigureImage
  20. from matplotlib.layout_engine import LayoutEngine
  21. from matplotlib.legend import Legend
  22. from matplotlib.lines import Line2D
  23. from matplotlib.patches import Rectangle, Patch
  24. from matplotlib.text import Text
  25. from matplotlib.transforms import Affine2D, Bbox, BboxBase, Transform
  26. from mpl_toolkits.mplot3d import Axes3D
  27. from .typing import ColorType, HashableList
  28. _T = TypeVar("_T")
  29. class FigureBase(Artist):
  30. artists: list[Artist]
  31. lines: list[Line2D]
  32. patches: list[Patch]
  33. texts: list[Text]
  34. images: list[_ImageBase]
  35. legends: list[Legend]
  36. subfigs: list[SubFigure]
  37. stale: bool
  38. suppressComposite: bool | None
  39. def __init__(self, **kwargs) -> None: ...
  40. def autofmt_xdate(
  41. self,
  42. bottom: float = ...,
  43. rotation: int = ...,
  44. ha: Literal["left", "center", "right"] = ...,
  45. which: Literal["major", "minor", "both"] = ...,
  46. ) -> None: ...
  47. def get_children(self) -> list[Artist]: ...
  48. def contains(self, mouseevent: MouseEvent) -> tuple[bool, dict[Any, Any]]: ...
  49. def suptitle(self, t: str, **kwargs) -> Text: ...
  50. def get_suptitle(self) -> str: ...
  51. def supxlabel(self, t: str, **kwargs) -> Text: ...
  52. def get_supxlabel(self) -> str: ...
  53. def supylabel(self, t: str, **kwargs) -> Text: ...
  54. def get_supylabel(self) -> str: ...
  55. def get_edgecolor(self) -> ColorType: ...
  56. def get_facecolor(self) -> ColorType: ...
  57. def get_frameon(self) -> bool: ...
  58. def set_linewidth(self, linewidth: float) -> None: ...
  59. def get_linewidth(self) -> float: ...
  60. def set_edgecolor(self, color: ColorType) -> None: ...
  61. def set_facecolor(self, color: ColorType) -> None: ...
  62. @overload
  63. def get_figure(self, root: Literal[True]) -> Figure: ...
  64. @overload
  65. def get_figure(self, root: Literal[False]) -> Figure | SubFigure: ...
  66. @overload
  67. def get_figure(self, root: bool = ...) -> Figure | SubFigure: ...
  68. def set_frameon(self, b: bool) -> None: ...
  69. @property
  70. def frameon(self) -> bool: ...
  71. @frameon.setter
  72. def frameon(self, b: bool) -> None: ...
  73. def add_artist(self, artist: Artist, clip: bool = ...) -> Artist: ...
  74. @overload
  75. def add_axes(self, ax: Axes) -> Axes: ...
  76. @overload
  77. def add_axes(
  78. self,
  79. rect: tuple[float, float, float, float],
  80. projection: None | str = ...,
  81. polar: bool = ...,
  82. **kwargs
  83. ) -> Axes: ...
  84. # TODO: docstring indicates SubplotSpec a valid arg, but none of the listed signatures appear to be that
  85. @overload
  86. def add_subplot(self, *args: Any, projection: Literal["3d"], **kwargs: Any) -> Axes3D: ...
  87. @overload
  88. def add_subplot(
  89. self, nrows: int, ncols: int, index: int | tuple[int, int], **kwargs: Any
  90. ) -> Axes: ...
  91. @overload
  92. def add_subplot(self, pos: int, **kwargs: Any) -> Axes: ...
  93. @overload
  94. def add_subplot(self, ax: Axes, **kwargs: Any) -> Axes: ...
  95. @overload
  96. def add_subplot(self, ax: SubplotSpec, **kwargs: Any) -> Axes: ...
  97. @overload
  98. def add_subplot(self, **kwargs: Any) -> Axes: ...
  99. @overload
  100. def subplots(
  101. self,
  102. nrows: Literal[1] = ...,
  103. ncols: Literal[1] = ...,
  104. *,
  105. sharex: bool | Literal["none", "all", "row", "col"] = ...,
  106. sharey: bool | Literal["none", "all", "row", "col"] = ...,
  107. squeeze: Literal[True] = ...,
  108. width_ratios: Sequence[float] | None = ...,
  109. height_ratios: Sequence[float] | None = ...,
  110. subplot_kw: dict[str, Any] | None = ...,
  111. gridspec_kw: dict[str, Any] | None = ...,
  112. ) -> Axes: ...
  113. @overload
  114. def subplots(
  115. self,
  116. nrows: int = ...,
  117. ncols: int = ...,
  118. *,
  119. sharex: bool | Literal["none", "all", "row", "col"] = ...,
  120. sharey: bool | Literal["none", "all", "row", "col"] = ...,
  121. squeeze: Literal[False],
  122. width_ratios: Sequence[float] | None = ...,
  123. height_ratios: Sequence[float] | None = ...,
  124. subplot_kw: dict[str, Any] | None = ...,
  125. gridspec_kw: dict[str, Any] | None = ...,
  126. ) -> np.ndarray: ... # TODO numpy/numpy#24738
  127. @overload
  128. def subplots(
  129. self,
  130. nrows: int = ...,
  131. ncols: int = ...,
  132. *,
  133. sharex: bool | Literal["none", "all", "row", "col"] = ...,
  134. sharey: bool | Literal["none", "all", "row", "col"] = ...,
  135. squeeze: bool = ...,
  136. width_ratios: Sequence[float] | None = ...,
  137. height_ratios: Sequence[float] | None = ...,
  138. subplot_kw: dict[str, Any] | None = ...,
  139. gridspec_kw: dict[str, Any] | None = ...,
  140. ) -> Any: ...
  141. def delaxes(self, ax: Axes) -> None: ...
  142. def clear(self, keep_observers: bool = ...) -> None: ...
  143. def clf(self, keep_observers: bool = ...) -> None: ...
  144. @overload
  145. def legend(self) -> Legend: ...
  146. @overload
  147. def legend(self, handles: Iterable[Artist], labels: Iterable[str], **kwargs) -> Legend: ...
  148. @overload
  149. def legend(self, *, handles: Iterable[Artist], **kwargs) -> Legend: ...
  150. @overload
  151. def legend(self, labels: Iterable[str], **kwargs) -> Legend: ...
  152. @overload
  153. def legend(self, **kwargs) -> Legend: ...
  154. def text(
  155. self,
  156. x: float,
  157. y: float,
  158. s: str,
  159. fontdict: dict[str, Any] | None = ...,
  160. **kwargs
  161. ) -> Text: ...
  162. def colorbar(
  163. self,
  164. mappable: ScalarMappable | ColorizingArtist,
  165. cax: Axes | None = ...,
  166. ax: Axes | Iterable[Axes] | None = ...,
  167. use_gridspec: bool = ...,
  168. **kwargs
  169. ) -> Colorbar: ...
  170. def subplots_adjust(
  171. self,
  172. left: float | None = ...,
  173. bottom: float | None = ...,
  174. right: float | None = ...,
  175. top: float | None = ...,
  176. wspace: float | None = ...,
  177. hspace: float | None = ...,
  178. ) -> None: ...
  179. def align_xlabels(self, axs: Iterable[Axes] | None = ...) -> None: ...
  180. def align_ylabels(self, axs: Iterable[Axes] | None = ...) -> None: ...
  181. def align_titles(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) -> ColorizingArtist | 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. @property
  266. def figure(self) -> Figure: ...
  267. subplotpars: SubplotParams
  268. dpi_scale_trans: Affine2D
  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 canvas(self) -> FigureCanvasBase: ...
  288. @property
  289. def dpi(self) -> float: ...
  290. @dpi.setter
  291. def dpi(self, value: float) -> None: ...
  292. def get_dpi(self) -> float: ...
  293. def set_dpi(self, val) -> None: ...
  294. def get_constrained_layout(self) -> bool: ...
  295. def get_constrained_layout_pads(
  296. self, relative: bool = ...
  297. ) -> tuple[float, float, float, float]: ...
  298. def get_layout_engine(self) -> LayoutEngine: ...
  299. @property # type: ignore[misc]
  300. def axes(self) -> list[Axes]: ... # type: ignore[override]
  301. def get_axes(self) -> list[Axes]: ...
  302. class Figure(FigureBase):
  303. @property
  304. def figure(self) -> Figure: ...
  305. bbox_inches: Bbox
  306. dpi_scale_trans: Affine2D
  307. bbox: BboxBase
  308. figbbox: BboxBase
  309. transFigure: Transform
  310. transSubfigure: Transform
  311. patch: Rectangle
  312. subplotpars: SubplotParams
  313. def __init__(
  314. self,
  315. figsize: tuple[float, float] | None = ...,
  316. dpi: float | None = ...,
  317. *,
  318. facecolor: ColorType | None = ...,
  319. edgecolor: ColorType | None = ...,
  320. linewidth: float = ...,
  321. frameon: bool | None = ...,
  322. subplotpars: SubplotParams | None = ...,
  323. tight_layout: bool | dict[str, Any] | None = ...,
  324. constrained_layout: bool | dict[str, Any] | None = ...,
  325. layout: Literal["constrained", "compressed", "tight"]
  326. | LayoutEngine
  327. | None = ...,
  328. **kwargs
  329. ) -> None: ...
  330. def pick(self, mouseevent: MouseEvent) -> None: ...
  331. def set_layout_engine(
  332. self,
  333. layout: Literal["constrained", "compressed", "tight", "none"]
  334. | LayoutEngine
  335. | None = ...,
  336. **kwargs
  337. ) -> None: ...
  338. def get_layout_engine(self) -> LayoutEngine | None: ...
  339. def _repr_html_(self) -> str | None: ...
  340. def show(self, warn: bool = ...) -> None: ...
  341. @property
  342. def number(self) -> int | str: ...
  343. @number.setter
  344. def number(self, num: int | str) -> None: ...
  345. @property # type: ignore[misc]
  346. def axes(self) -> list[Axes]: ... # type: ignore[override]
  347. def get_axes(self) -> list[Axes]: ...
  348. @property
  349. def dpi(self) -> float: ...
  350. @dpi.setter
  351. def dpi(self, dpi: float) -> None: ...
  352. def get_tight_layout(self) -> bool: ...
  353. def get_constrained_layout_pads(
  354. self, relative: bool = ...
  355. ) -> tuple[float, float, float, float]: ...
  356. def get_constrained_layout(self) -> bool: ...
  357. canvas: FigureCanvasBase
  358. def set_canvas(self, canvas: FigureCanvasBase) -> None: ...
  359. def figimage(
  360. self,
  361. X: ArrayLike,
  362. xo: int = ...,
  363. yo: int = ...,
  364. alpha: float | None = ...,
  365. norm: str | Normalize | None = ...,
  366. cmap: str | Colormap | None = ...,
  367. vmin: float | None = ...,
  368. vmax: float | None = ...,
  369. origin: Literal["upper", "lower"] | None = ...,
  370. resize: bool = ...,
  371. *,
  372. colorizer: Colorizer | None = ...,
  373. **kwargs
  374. ) -> FigureImage: ...
  375. def set_size_inches(
  376. self, w: float | tuple[float, float], h: float | None = ..., forward: bool = ...
  377. ) -> None: ...
  378. def get_size_inches(self) -> np.ndarray: ...
  379. def get_figwidth(self) -> float: ...
  380. def get_figheight(self) -> float: ...
  381. def get_dpi(self) -> float: ...
  382. def set_dpi(self, val: float) -> None: ...
  383. def set_figwidth(self, val: float, forward: bool = ...) -> None: ...
  384. def set_figheight(self, val: float, forward: bool = ...) -> None: ...
  385. def clear(self, keep_observers: bool = ...) -> None: ...
  386. def draw_without_rendering(self) -> None: ...
  387. def draw_artist(self, a: Artist) -> None: ...
  388. def add_axobserver(self, func: Callable[[Figure], Any]) -> None: ...
  389. def savefig(
  390. self,
  391. fname: str | os.PathLike | IO,
  392. *,
  393. transparent: bool | None = ...,
  394. **kwargs
  395. ) -> None: ...
  396. def ginput(
  397. self,
  398. n: int = ...,
  399. timeout: float = ...,
  400. show_clicks: bool = ...,
  401. mouse_add: MouseButton = ...,
  402. mouse_pop: MouseButton = ...,
  403. mouse_stop: MouseButton = ...,
  404. ) -> list[tuple[int, int]]: ...
  405. def waitforbuttonpress(self, timeout: float = ...) -> None | bool: ...
  406. def tight_layout(
  407. self,
  408. *,
  409. pad: float = ...,
  410. h_pad: float | None = ...,
  411. w_pad: float | None = ...,
  412. rect: tuple[float, float, float, float] | None = ...
  413. ) -> None: ...
  414. def figaspect(
  415. arg: float | ArrayLike,
  416. ) -> np.ndarray[tuple[Literal[2]], np.dtype[np.float64]]: ...