backend_bases.pyi 16 KB

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