image.pyi 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. from collections.abc import Callable, Sequence
  2. import os
  3. import pathlib
  4. from typing import Any, BinaryIO, Literal
  5. import numpy as np
  6. from numpy.typing import ArrayLike, NDArray
  7. import PIL.Image
  8. from matplotlib.axes import Axes
  9. from matplotlib import colorizer
  10. from matplotlib.backend_bases import RendererBase, MouseEvent
  11. from matplotlib.colorizer import Colorizer
  12. from matplotlib.colors import Colormap, Normalize
  13. from matplotlib.figure import Figure
  14. from matplotlib.transforms import Affine2D, BboxBase, Bbox, Transform
  15. #
  16. # These names are re-exported from matplotlib._image.
  17. #
  18. BESSEL: int
  19. BICUBIC: int
  20. BILINEAR: int
  21. BLACKMAN: int
  22. CATROM: int
  23. GAUSSIAN: int
  24. HAMMING: int
  25. HANNING: int
  26. HERMITE: int
  27. KAISER: int
  28. LANCZOS: int
  29. MITCHELL: int
  30. NEAREST: int
  31. QUADRIC: int
  32. SINC: int
  33. SPLINE16: int
  34. SPLINE36: int
  35. def resample(
  36. input_array: NDArray[np.float32] | NDArray[np.float64] | NDArray[np.int8],
  37. output_array: NDArray[np.float32] | NDArray[np.float64] | NDArray[np.int8],
  38. transform: Transform,
  39. interpolation: int = ...,
  40. resample: bool = ...,
  41. alpha: float = ...,
  42. norm: bool = ...,
  43. radius: float = ...,
  44. ) -> None: ...
  45. #
  46. # END names re-exported from matplotlib._image.
  47. #
  48. interpolations_names: set[str]
  49. def composite_images(
  50. images: Sequence[_ImageBase], renderer: RendererBase, magnification: float = ...
  51. ) -> tuple[np.ndarray, float, float]: ...
  52. class _ImageBase(colorizer.ColorizingArtist):
  53. zorder: float
  54. origin: Literal["upper", "lower"]
  55. axes: Axes
  56. def __init__(
  57. self,
  58. ax: Axes,
  59. cmap: str | Colormap | None = ...,
  60. norm: str | Normalize | None = ...,
  61. colorizer: Colorizer | None = ...,
  62. interpolation: str | None = ...,
  63. origin: Literal["upper", "lower"] | None = ...,
  64. filternorm: bool = ...,
  65. filterrad: float = ...,
  66. resample: bool | None = ...,
  67. *,
  68. interpolation_stage: Literal["data", "rgba", "auto"] | None = ...,
  69. **kwargs
  70. ) -> None: ...
  71. def get_size(self) -> tuple[int, int]: ...
  72. def set_alpha(self, alpha: float | ArrayLike | None) -> None: ...
  73. def changed(self) -> None: ...
  74. def make_image(
  75. self, renderer: RendererBase, magnification: float = ..., unsampled: bool = ...
  76. ) -> tuple[np.ndarray, float, float, Affine2D]: ...
  77. def draw(self, renderer: RendererBase) -> None: ...
  78. def write_png(self, fname: str | pathlib.Path | BinaryIO) -> None: ...
  79. def set_data(self, A: ArrayLike | None) -> None: ...
  80. def set_array(self, A: ArrayLike | None) -> None: ...
  81. def get_shape(self) -> tuple[int, int, int]: ...
  82. def get_interpolation(self) -> str: ...
  83. def set_interpolation(self, s: str | None) -> None: ...
  84. def get_interpolation_stage(self) -> Literal["data", "rgba", "auto"]: ...
  85. def set_interpolation_stage(self, s: Literal["data", "rgba", "auto"]) -> None: ...
  86. def can_composite(self) -> bool: ...
  87. def set_resample(self, v: bool | None) -> None: ...
  88. def get_resample(self) -> bool: ...
  89. def set_filternorm(self, filternorm: bool) -> None: ...
  90. def get_filternorm(self) -> bool: ...
  91. def set_filterrad(self, filterrad: float) -> None: ...
  92. def get_filterrad(self) -> float: ...
  93. class AxesImage(_ImageBase):
  94. def __init__(
  95. self,
  96. ax: Axes,
  97. *,
  98. cmap: str | Colormap | None = ...,
  99. norm: str | Normalize | None = ...,
  100. colorizer: Colorizer | None = ...,
  101. interpolation: str | None = ...,
  102. origin: Literal["upper", "lower"] | None = ...,
  103. extent: tuple[float, float, float, float] | None = ...,
  104. filternorm: bool = ...,
  105. filterrad: float = ...,
  106. resample: bool = ...,
  107. interpolation_stage: Literal["data", "rgba", "auto"] | None = ...,
  108. **kwargs
  109. ) -> None: ...
  110. def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox: ...
  111. def make_image(
  112. self, renderer: RendererBase, magnification: float = ..., unsampled: bool = ...
  113. ) -> tuple[np.ndarray, float, float, Affine2D]: ...
  114. def set_extent(
  115. self, extent: tuple[float, float, float, float], **kwargs
  116. ) -> None: ...
  117. def get_extent(self) -> tuple[float, float, float, float]: ...
  118. def get_cursor_data(self, event: MouseEvent) -> None | float: ...
  119. class NonUniformImage(AxesImage):
  120. mouseover: bool
  121. def __init__(
  122. self, ax: Axes, *, interpolation: Literal["nearest", "bilinear"] = ..., **kwargs
  123. ) -> None: ...
  124. def set_data(self, x: ArrayLike, y: ArrayLike, A: ArrayLike) -> None: ... # type: ignore[override]
  125. # more limited interpolation available here than base class
  126. def set_interpolation(self, s: Literal["nearest", "bilinear"]) -> None: ... # type: ignore[override]
  127. class PcolorImage(AxesImage):
  128. def __init__(
  129. self,
  130. ax: Axes,
  131. x: ArrayLike | None = ...,
  132. y: ArrayLike | None = ...,
  133. A: ArrayLike | None = ...,
  134. *,
  135. cmap: str | Colormap | None = ...,
  136. norm: str | Normalize | None = ...,
  137. colorizer: Colorizer | None = ...,
  138. **kwargs
  139. ) -> None: ...
  140. def set_data(self, x: ArrayLike, y: ArrayLike, A: ArrayLike) -> None: ... # type: ignore[override]
  141. class FigureImage(_ImageBase):
  142. zorder: float
  143. figure: Figure
  144. ox: float
  145. oy: float
  146. magnification: float
  147. def __init__(
  148. self,
  149. fig: Figure,
  150. *,
  151. cmap: str | Colormap | None = ...,
  152. norm: str | Normalize | None = ...,
  153. colorizer: Colorizer | None = ...,
  154. offsetx: int = ...,
  155. offsety: int = ...,
  156. origin: Literal["upper", "lower"] | None = ...,
  157. **kwargs
  158. ) -> None: ...
  159. def get_extent(self) -> tuple[float, float, float, float]: ...
  160. class BboxImage(_ImageBase):
  161. bbox: BboxBase
  162. def __init__(
  163. self,
  164. bbox: BboxBase | Callable[[RendererBase | None], Bbox],
  165. *,
  166. cmap: str | Colormap | None = ...,
  167. norm: str | Normalize | None = ...,
  168. colorizer: Colorizer | None = ...,
  169. interpolation: str | None = ...,
  170. origin: Literal["upper", "lower"] | None = ...,
  171. filternorm: bool = ...,
  172. filterrad: float = ...,
  173. resample: bool = ...,
  174. **kwargs
  175. ) -> None: ...
  176. def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox: ...
  177. def imread(
  178. fname: str | pathlib.Path | BinaryIO, format: str | None = ...
  179. ) -> np.ndarray: ...
  180. def imsave(
  181. fname: str | os.PathLike | BinaryIO,
  182. arr: ArrayLike,
  183. vmin: float | None = ...,
  184. vmax: float | None = ...,
  185. cmap: str | Colormap | None = ...,
  186. format: str | None = ...,
  187. origin: Literal["upper", "lower"] | None = ...,
  188. dpi: float = ...,
  189. *,
  190. metadata: dict[str, str] | None = ...,
  191. pil_kwargs: dict[str, Any] | None = ...
  192. ) -> None: ...
  193. def pil_to_array(pilImage: PIL.Image.Image) -> np.ndarray: ...
  194. def thumbnail(
  195. infile: str | BinaryIO,
  196. thumbfile: str | BinaryIO,
  197. scale: float = ...,
  198. interpolation: str = ...,
  199. preview: bool = ...,
  200. ) -> Figure: ...