backend_bases.pyi 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. from enum import Enum, IntEnum
  2. import os
  3. from matplotlib import (
  4. cbook,
  5. transforms,
  6. widgets,
  7. _api,
  8. )
  9. from matplotlib.artist import Artist
  10. from matplotlib.axes import Axes
  11. from matplotlib.backend_managers import ToolManager
  12. from matplotlib.backend_tools import Cursors, ToolBase
  13. from matplotlib.colorbar import Colorbar
  14. from matplotlib.figure import Figure
  15. from matplotlib.font_manager import FontProperties
  16. from matplotlib.path import Path
  17. from matplotlib.texmanager import TexManager
  18. from matplotlib.text import Text
  19. from matplotlib.transforms import Bbox, BboxBase, Transform, TransformedPath
  20. from collections.abc import Callable, Iterable, Sequence
  21. from typing import Any, IO, Literal, NamedTuple, TypeVar
  22. from numpy.typing import ArrayLike
  23. from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType
  24. def register_backend(
  25. format: str, backend: str | type[FigureCanvasBase], description: str | None = ...
  26. ) -> None: ...
  27. def get_registered_canvas_class(format: str) -> type[FigureCanvasBase]: ...
  28. class RendererBase:
  29. def __init__(self) -> None: ...
  30. def open_group(self, s: str, gid: str | None = ...) -> None: ...
  31. def close_group(self, s: str) -> None: ...
  32. def draw_path(
  33. self,
  34. gc: GraphicsContextBase,
  35. path: Path,
  36. transform: Transform,
  37. rgbFace: ColorType | None = ...,
  38. ) -> None: ...
  39. def draw_markers(
  40. self,
  41. gc: GraphicsContextBase,
  42. marker_path: Path,
  43. marker_trans: Transform,
  44. path: Path,
  45. trans: Transform,
  46. rgbFace: ColorType | None = ...,
  47. ) -> None: ...
  48. def draw_path_collection(
  49. self,
  50. gc: GraphicsContextBase,
  51. master_transform: Transform,
  52. paths: Sequence[Path],
  53. all_transforms: Sequence[ArrayLike],
  54. offsets: ArrayLike | Sequence[ArrayLike],
  55. offset_trans: Transform,
  56. facecolors: ColorType | Sequence[ColorType],
  57. edgecolors: ColorType | Sequence[ColorType],
  58. linewidths: float | Sequence[float],
  59. linestyles: LineStyleType | Sequence[LineStyleType],
  60. antialiaseds: bool | Sequence[bool],
  61. urls: str | Sequence[str],
  62. offset_position: Any,
  63. ) -> None: ...
  64. def draw_quad_mesh(
  65. self,
  66. gc: GraphicsContextBase,
  67. master_transform: Transform,
  68. meshWidth,
  69. meshHeight,
  70. coordinates: ArrayLike,
  71. offsets: ArrayLike | Sequence[ArrayLike],
  72. offsetTrans: Transform,
  73. facecolors: Sequence[ColorType],
  74. antialiased: bool,
  75. edgecolors: Sequence[ColorType] | ColorType | None,
  76. ) -> None: ...
  77. def draw_gouraud_triangle(
  78. self,
  79. gc: GraphicsContextBase,
  80. points: ArrayLike,
  81. colors: ArrayLike,
  82. transform: Transform,
  83. ) -> None: ...
  84. def draw_gouraud_triangles(
  85. self,
  86. gc: GraphicsContextBase,
  87. triangles_array: ArrayLike,
  88. colors_array: ArrayLike,
  89. transform: Transform,
  90. ) -> None: ...
  91. def get_image_magnification(self) -> float: ...
  92. def draw_image(
  93. self,
  94. gc: GraphicsContextBase,
  95. x: float,
  96. y: float,
  97. im: ArrayLike,
  98. transform: transforms.Affine2DBase | None = ...,
  99. ) -> None: ...
  100. def option_image_nocomposite(self) -> bool: ...
  101. def option_scale_image(self) -> bool: ...
  102. def draw_tex(
  103. self,
  104. gc: GraphicsContextBase,
  105. x: float,
  106. y: float,
  107. s: str,
  108. prop: FontProperties,
  109. angle: float,
  110. *,
  111. mtext: Text | None = ...
  112. ) -> None: ...
  113. def draw_text(
  114. self,
  115. gc: GraphicsContextBase,
  116. x: float,
  117. y: float,
  118. s: str,
  119. prop: FontProperties,
  120. angle: float,
  121. ismath: bool | Literal["TeX"] = ...,
  122. mtext: Text | None = ...,
  123. ) -> None: ...
  124. def get_text_width_height_descent(
  125. self, s: str, prop: FontProperties, ismath: bool | Literal["TeX"]
  126. ) -> tuple[float, float, float]: ...
  127. def flipy(self) -> bool: ...
  128. def get_canvas_width_height(self) -> tuple[float, float]: ...
  129. def get_texmanager(self) -> TexManager: ...
  130. def new_gc(self) -> GraphicsContextBase: ...
  131. def points_to_pixels(self, points: ArrayLike) -> ArrayLike: ...
  132. def start_rasterizing(self) -> None: ...
  133. def stop_rasterizing(self) -> None: ...
  134. def start_filter(self) -> None: ...
  135. def stop_filter(self, filter_func) -> None: ...
  136. class GraphicsContextBase:
  137. def __init__(self) -> None: ...
  138. def copy_properties(self, gc: GraphicsContextBase) -> None: ...
  139. def restore(self) -> None: ...
  140. def get_alpha(self) -> float: ...
  141. def get_antialiased(self) -> int: ...
  142. def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
  143. def get_clip_rectangle(self) -> Bbox | None: ...
  144. def get_clip_path(
  145. self,
  146. ) -> tuple[TransformedPath, Transform] | tuple[None, None]: ...
  147. def get_dashes(self) -> tuple[float, ArrayLike | None]: ...
  148. def get_forced_alpha(self) -> bool: ...
  149. def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
  150. def get_linewidth(self) -> float: ...
  151. def get_rgb(self) -> tuple[float, float, float, float]: ...
  152. def get_url(self) -> str | None: ...
  153. def get_gid(self) -> int | None: ...
  154. def get_snap(self) -> bool | None: ...
  155. def set_alpha(self, alpha: float) -> None: ...
  156. def set_antialiased(self, b: bool) -> None: ...
  157. def set_capstyle(self, cs: CapStyleType) -> None: ...
  158. def set_clip_rectangle(self, rectangle: Bbox | None) -> None: ...
  159. def set_clip_path(self, path: TransformedPath | None) -> None: ...
  160. def set_dashes(self, dash_offset: float, dash_list: ArrayLike | None) -> None: ...
  161. def set_foreground(self, fg: ColorType, isRGBA: bool = ...) -> None: ...
  162. def set_joinstyle(self, js: JoinStyleType) -> None: ...
  163. def set_linewidth(self, w: float) -> None: ...
  164. def set_url(self, url: str | None) -> None: ...
  165. def set_gid(self, id: int | None) -> None: ...
  166. def set_snap(self, snap: bool | None) -> None: ...
  167. def set_hatch(self, hatch: str | None) -> None: ...
  168. def get_hatch(self) -> str | None: ...
  169. def get_hatch_path(self, density: float = ...) -> Path: ...
  170. def get_hatch_color(self) -> ColorType: ...
  171. def set_hatch_color(self, hatch_color: ColorType) -> None: ...
  172. def get_hatch_linewidth(self) -> float: ...
  173. def get_sketch_params(self) -> tuple[float, float, float] | None: ...
  174. def set_sketch_params(
  175. self,
  176. scale: float | None = ...,
  177. length: float | None = ...,
  178. randomness: float | None = ...,
  179. ) -> None: ...
  180. class TimerBase:
  181. callbacks: list[tuple[Callable, tuple, dict[str, Any]]]
  182. def __init__(
  183. self,
  184. interval: int | None = ...,
  185. callbacks: list[tuple[Callable, tuple, dict[str, Any]]] | None = ...,
  186. ) -> None: ...
  187. def __del__(self) -> None: ...
  188. def start(self, interval: int | None = ...) -> None: ...
  189. def stop(self) -> None: ...
  190. @property
  191. def interval(self) -> int: ...
  192. @interval.setter
  193. def interval(self, interval: int) -> None: ...
  194. @property
  195. def single_shot(self) -> bool: ...
  196. @single_shot.setter
  197. def single_shot(self, ss: bool) -> None: ...
  198. def add_callback(self, func: Callable, *args, **kwargs) -> Callable: ...
  199. def remove_callback(self, func: Callable, *args, **kwargs) -> None: ...
  200. class Event:
  201. name: str
  202. canvas: FigureCanvasBase
  203. def __init__(
  204. self, name: str, canvas: FigureCanvasBase, guiEvent: Any | None = ...
  205. ) -> None: ...
  206. @property
  207. def guiEvent(self) -> Any: ...
  208. class DrawEvent(Event):
  209. renderer: RendererBase
  210. def __init__(
  211. self, name: str, canvas: FigureCanvasBase, renderer: RendererBase
  212. ) -> None: ...
  213. class ResizeEvent(Event):
  214. width: int
  215. height: int
  216. def __init__(self, name: str, canvas: FigureCanvasBase) -> None: ...
  217. class CloseEvent(Event): ...
  218. class LocationEvent(Event):
  219. lastevent: Event | None
  220. x: int
  221. y: int
  222. inaxes: Axes | None
  223. xdata: float | None
  224. ydata: float | None
  225. def __init__(
  226. self,
  227. name: str,
  228. canvas: FigureCanvasBase,
  229. x: int,
  230. y: int,
  231. guiEvent: Any | None = ...,
  232. *,
  233. modifiers: Iterable[str] | None = ...,
  234. ) -> None: ...
  235. class MouseButton(IntEnum):
  236. LEFT: int
  237. MIDDLE: int
  238. RIGHT: int
  239. BACK: int
  240. FORWARD: int
  241. class MouseEvent(LocationEvent):
  242. button: MouseButton | Literal["up", "down"] | None
  243. key: str | None
  244. step: float
  245. dblclick: bool
  246. def __init__(
  247. self,
  248. name: str,
  249. canvas: FigureCanvasBase,
  250. x: int,
  251. y: int,
  252. button: MouseButton | Literal["up", "down"] | None = ...,
  253. key: str | None = ...,
  254. step: float = ...,
  255. dblclick: bool = ...,
  256. guiEvent: Any | None = ...,
  257. *,
  258. modifiers: Iterable[str] | None = ...,
  259. ) -> None: ...
  260. class PickEvent(Event):
  261. mouseevent: MouseEvent
  262. artist: Artist
  263. def __init__(
  264. self,
  265. name: str,
  266. canvas: FigureCanvasBase,
  267. mouseevent: MouseEvent,
  268. artist: Artist,
  269. guiEvent: Any | None = ...,
  270. **kwargs
  271. ) -> None: ...
  272. class KeyEvent(LocationEvent):
  273. key: str | None
  274. def __init__(
  275. self,
  276. name: str,
  277. canvas: FigureCanvasBase,
  278. key: str | None,
  279. x: int = ...,
  280. y: int = ...,
  281. guiEvent: Any | None = ...,
  282. ) -> None: ...
  283. class FigureCanvasBase:
  284. required_interactive_framework: str | None
  285. @_api.classproperty
  286. def manager_class(cls) -> type[FigureManagerBase]: ...
  287. events: list[str]
  288. fixed_dpi: None | float
  289. filetypes: dict[str, str]
  290. @_api.classproperty
  291. def supports_blit(cls) -> bool: ...
  292. figure: Figure
  293. manager: None | FigureManagerBase
  294. widgetlock: widgets.LockDraw
  295. mouse_grabber: None | Axes
  296. toolbar: None | NavigationToolbar2
  297. def __init__(self, figure: Figure | None = ...) -> None: ...
  298. @property
  299. def callbacks(self) -> cbook.CallbackRegistry: ...
  300. @property
  301. def button_pick_id(self) -> int: ...
  302. @property
  303. def scroll_pick_id(self) -> int: ...
  304. @classmethod
  305. def new_manager(cls, figure: Figure, num: int | str) -> FigureManagerBase: ...
  306. def is_saving(self) -> bool: ...
  307. def blit(self, bbox: BboxBase | None = ...) -> None: ...
  308. def inaxes(self, xy: tuple[float, float]) -> Axes | None: ...
  309. def grab_mouse(self, ax: Axes) -> None: ...
  310. def release_mouse(self, ax: Axes) -> None: ...
  311. def set_cursor(self, cursor: Cursors) -> None: ...
  312. def draw(self, *args, **kwargs) -> None: ...
  313. def draw_idle(self, *args, **kwargs) -> None: ...
  314. @property
  315. def device_pixel_ratio(self) -> float: ...
  316. def get_width_height(self, *, physical: bool = ...) -> tuple[int, int]: ...
  317. @classmethod
  318. def get_supported_filetypes(cls) -> dict[str, str]: ...
  319. @classmethod
  320. def get_supported_filetypes_grouped(cls) -> dict[str, list[str]]: ...
  321. def print_figure(
  322. self,
  323. filename: str | os.PathLike | IO,
  324. dpi: float | None = ...,
  325. facecolor: ColorType | Literal["auto"] | None = ...,
  326. edgecolor: ColorType | Literal["auto"] | None = ...,
  327. orientation: str = ...,
  328. format: str | None = ...,
  329. *,
  330. bbox_inches: Literal["tight"] | Bbox | None = ...,
  331. pad_inches: float | None = ...,
  332. bbox_extra_artists: list[Artist] | None = ...,
  333. backend: str | None = ...,
  334. **kwargs
  335. ) -> Any: ...
  336. @classmethod
  337. def get_default_filetype(cls) -> str: ...
  338. def get_default_filename(self) -> str: ...
  339. _T = TypeVar("_T", bound=FigureCanvasBase)
  340. def switch_backends(self, FigureCanvasClass: type[_T]) -> _T: ...
  341. def mpl_connect(self, s: str, func: Callable[[Event], Any]) -> int: ...
  342. def mpl_disconnect(self, cid: int) -> None: ...
  343. def new_timer(
  344. self,
  345. interval: int | None = ...,
  346. callbacks: list[tuple[Callable, tuple, dict[str, Any]]] | None = ...,
  347. ) -> TimerBase: ...
  348. def flush_events(self) -> None: ...
  349. def start_event_loop(self, timeout: float = ...) -> None: ...
  350. def stop_event_loop(self) -> None: ...
  351. def key_press_handler(
  352. event: KeyEvent,
  353. canvas: FigureCanvasBase | None = ...,
  354. toolbar: NavigationToolbar2 | None = ...,
  355. ) -> None: ...
  356. def button_press_handler(
  357. event: MouseEvent,
  358. canvas: FigureCanvasBase | None = ...,
  359. toolbar: NavigationToolbar2 | None = ...,
  360. ) -> None: ...
  361. class NonGuiException(Exception): ...
  362. class FigureManagerBase:
  363. canvas: FigureCanvasBase
  364. num: int | str
  365. key_press_handler_id: int | None
  366. button_press_handler_id: int | None
  367. toolmanager: ToolManager | None
  368. toolbar: NavigationToolbar2 | ToolContainerBase | None
  369. def __init__(self, canvas: FigureCanvasBase, num: int | str) -> None: ...
  370. @classmethod
  371. def create_with_canvas(
  372. cls, canvas_class: type[FigureCanvasBase], figure: Figure, num: int | str
  373. ) -> FigureManagerBase: ...
  374. @classmethod
  375. def start_main_loop(cls) -> None: ...
  376. @classmethod
  377. def pyplot_show(cls, *, block: bool | None = ...) -> None: ...
  378. def show(self) -> None: ...
  379. def destroy(self) -> None: ...
  380. def full_screen_toggle(self) -> None: ...
  381. def resize(self, w: int, h: int) -> None: ...
  382. def get_window_title(self) -> str: ...
  383. def set_window_title(self, title: str) -> None: ...
  384. cursors = Cursors
  385. class _Mode(str, Enum):
  386. NONE: str
  387. PAN: str
  388. ZOOM: str
  389. class NavigationToolbar2:
  390. toolitems: tuple[tuple[str, ...] | tuple[None, ...], ...]
  391. canvas: FigureCanvasBase
  392. mode: _Mode
  393. def __init__(self, canvas: FigureCanvasBase) -> None: ...
  394. def set_message(self, s: str) -> None: ...
  395. def draw_rubberband(
  396. self, event: Event, x0: float, y0: float, x1: float, y1: float
  397. ) -> None: ...
  398. def remove_rubberband(self) -> None: ...
  399. def home(self, *args) -> None: ...
  400. def back(self, *args) -> None: ...
  401. def forward(self, *args) -> None: ...
  402. def mouse_move(self, event: MouseEvent) -> None: ...
  403. def pan(self, *args) -> None: ...
  404. class _PanInfo(NamedTuple):
  405. button: MouseButton
  406. axes: list[Axes]
  407. cid: int
  408. def press_pan(self, event: Event) -> None: ...
  409. def drag_pan(self, event: Event) -> None: ...
  410. def release_pan(self, event: Event) -> None: ...
  411. def zoom(self, *args) -> None: ...
  412. class _ZoomInfo(NamedTuple):
  413. direction: Literal["in", "out"]
  414. start_xy: tuple[float, float]
  415. axes: list[Axes]
  416. cid: int
  417. cbar: Colorbar
  418. def press_zoom(self, event: Event) -> None: ...
  419. def drag_zoom(self, event: Event) -> None: ...
  420. def release_zoom(self, event: Event) -> None: ...
  421. def push_current(self) -> None: ...
  422. subplot_tool: widgets.SubplotTool
  423. def configure_subplots(self, *args): ...
  424. def save_figure(self, *args) -> None: ...
  425. def update(self) -> None: ...
  426. def set_history_buttons(self) -> None: ...
  427. class ToolContainerBase:
  428. toolmanager: ToolManager
  429. def __init__(self, toolmanager: ToolManager) -> None: ...
  430. def add_tool(self, tool: ToolBase, group: str, position: int = ...) -> None: ...
  431. def trigger_tool(self, name: str) -> None: ...
  432. def add_toolitem(
  433. self,
  434. name: str,
  435. group: str,
  436. position: int,
  437. image: str,
  438. description: str,
  439. toggle: bool,
  440. ) -> None: ...
  441. def toggle_toolitem(self, name: str, toggled: bool) -> None: ...
  442. def remove_toolitem(self, name: str) -> None: ...
  443. def set_message(self, s: str) -> None: ...
  444. class _Backend:
  445. backend_version: str
  446. FigureCanvas: type[FigureCanvasBase] | None
  447. FigureManager: type[FigureManagerBase]
  448. mainloop: None | Callable[[], Any]
  449. @classmethod
  450. def new_figure_manager(cls, num: int | str, *args, **kwargs) -> FigureManagerBase: ...
  451. @classmethod
  452. def new_figure_manager_given_figure(cls, num: int | str, figure: Figure) -> FigureManagerBase: ...
  453. @classmethod
  454. def draw_if_interactive(cls) -> None: ...
  455. @classmethod
  456. def show(cls, *, block: bool | None = ...) -> None: ...
  457. @staticmethod
  458. def export(cls) -> type[_Backend]: ...
  459. class ShowBase(_Backend):
  460. def __call__(self, block: bool | None = ...) -> None: ...