diff --git a/lib/matplotlib/_path.pyi b/lib/matplotlib/_path.pyi index ee9c46483ec9..a0709c3b1f44 100644 --- a/lib/matplotlib/_path.pyi +++ b/lib/matplotlib/_path.pyi @@ -1,8 +1,7 @@ -from collections.abc import Sequence import numpy as np from .transforms import BboxBase def affine_transform(points: np.ndarray, trans: np.ndarray) -> np.ndarray: ... -def count_bboxes_overlapping_bbox(bbox: BboxBase, bboxes: Sequence[BboxBase]) -> int: ... +def count_bboxes_overlapping_bbox(bbox: BboxBase, bboxes: np.ndarray) -> int: ... diff --git a/lib/matplotlib/_qhull.pyi b/lib/matplotlib/_qhull.pyi index e69de29bb2d1..4aa575902e2a 100644 --- a/lib/matplotlib/_qhull.pyi +++ b/lib/matplotlib/_qhull.pyi @@ -0,0 +1,9 @@ +# Stub generated from the C++ (pybind11) signatures in ``src/_qhull_wrapper.cpp``. +# NOT verified with matplotlib's ``stubtest`` (the extension was not importable +# when this stub was written); treat the annotations as best-effort. +import numpy as np + +def delaunay( + x: np.ndarray, y: np.ndarray, verbose: int +) -> tuple[np.ndarray, np.ndarray]: ... +def version() -> str: ... diff --git a/lib/matplotlib/_tri.pyi b/lib/matplotlib/_tri.pyi index a0c710fc2309..bbefde330d28 100644 --- a/lib/matplotlib/_tri.pyi +++ b/lib/matplotlib/_tri.pyi @@ -28,7 +28,7 @@ class Triangulation: mask: npt.NDArray[np.bool_] | tuple[()], edges: npt.NDArray[np.int_] | tuple[()], neighbors: npt.NDArray[np.int_] | tuple[()], - correct_triangle_orientation: bool, + correct_triangle_orientations: bool, ): ... def calculate_plane_coefficients(self, z: npt.ArrayLike) -> npt.NDArray[np.float64]: ... def get_edges(self) -> npt.NDArray[np.int_]: ... diff --git a/lib/matplotlib/backends/_backend_agg.pyi b/lib/matplotlib/backends/_backend_agg.pyi index e69de29bb2d1..b925c2b5b286 100644 --- a/lib/matplotlib/backends/_backend_agg.pyi +++ b/lib/matplotlib/backends/_backend_agg.pyi @@ -0,0 +1,103 @@ +# Stub generated from the C++ (pybind11) signatures in +# ``src/_backend_agg_wrapper.cpp``. NOT verified with matplotlib's ``stubtest`` +# (the extension was not importable when this stub was written); the +# graphics-primitive argument types in particular are best-effort. +from collections.abc import Buffer, Sequence +from typing import overload + +import numpy as np + +from matplotlib.backend_bases import GraphicsContextBase +from matplotlib.path import Path +from matplotlib.transforms import Bbox, Transform + +class BufferRegion(Buffer): + # Not constructible from Python. + def set_x(self, x: int) -> None: ... + def set_y(self, y: int) -> None: ... + def get_extents(self) -> tuple[int, int, int, int]: ... + def __buffer__(self, flags: int, /) -> memoryview: ... + +class RendererAgg(Buffer): + def __init__(self, width: int, height: int, dpi: float) -> None: ... + def draw_path( + self, + gc: GraphicsContextBase, + path: Path, + trans: Transform, + face: np.ndarray | None = ..., + ) -> None: ... + def draw_markers( + self, + gc: GraphicsContextBase, + marker_path: Path, + marker_path_trans: Transform, + path: Path, + trans: Transform, + face: np.ndarray | None = ..., + ) -> None: ... + def draw_text_image( + self, + image: np.ndarray, + x: float, + y: float, + angle: float, + gc: GraphicsContextBase, + ) -> None: ... + def draw_image( + self, gc: GraphicsContextBase, x: float, y: float, image: np.ndarray + ) -> None: ... + def draw_path_collection( + self, + gc: GraphicsContextBase, + master_transform: Transform, + paths: Sequence[Path], + transforms: Sequence[np.ndarray], + offsets: np.ndarray, + offset_trans: Transform, + facecolors: np.ndarray, + edgecolors: np.ndarray, + linewidths: np.ndarray, + dashes: Sequence, + antialiaseds: np.ndarray, + ignored: object, + offset_position: object, + *, + hatchcolors: np.ndarray = ..., + ) -> None: ... + def draw_quad_mesh( + self, + gc: GraphicsContextBase, + master_transform: Transform, + mesh_width: int, + mesh_height: int, + coordinates: np.ndarray, + offsets: np.ndarray, + offset_trans: Transform, + facecolors: np.ndarray, + antialiased: bool, + edgecolors: np.ndarray, + ) -> None: ... + def draw_gouraud_triangles( + self, + gc: GraphicsContextBase, + points: np.ndarray, + colors: np.ndarray, + trans: Transform | None = ..., + ) -> None: ... + def clear(self) -> None: ... + def copy_from_bbox(self, bbox: Bbox) -> BufferRegion: ... + @overload + def restore_region(self, region: BufferRegion) -> None: ... + @overload + def restore_region( + self, + region: BufferRegion, + xx1: int, + yy1: int, + xx2: int, + yy2: int, + x: int, + y: int, + ) -> None: ... + def __buffer__(self, flags: int, /) -> memoryview: ... diff --git a/lib/matplotlib/backends/_macosx.pyi b/lib/matplotlib/backends/_macosx.pyi index e69de29bb2d1..5aee44476036 100644 --- a/lib/matplotlib/backends/_macosx.pyi +++ b/lib/matplotlib/backends/_macosx.pyi @@ -0,0 +1,38 @@ +# macOS-only native backend. Stub generated from the C types/methods in +# ``src/_macosx.m``. NOT verified with matplotlib's ``stubtest`` (the module is +# unavailable off-macOS and was not importable when this stub was written); the +# annotations, especially argument types, are best-effort. + +def event_loop_is_running() -> bool: ... +def wake_on_fd_write(fd: int) -> None: ... +def stop() -> None: ... +def show() -> None: ... +def choose_save_file( + title: str, directory: str, default_filename: str +) -> str | None: ... + +class FigureCanvas: + def update(self) -> None: ... + def flush_events(self) -> None: ... + def set_cursor(self, cursor: int) -> None: ... + def set_rubberband(self, x0: int, y0: int, x1: int, y1: int) -> None: ... + def remove_rubberband(self) -> None: ... + def _start_event_loop(self, timeout: float = ...) -> None: ... + def stop_event_loop(self) -> None: ... + +class FigureManager: + def _show(self) -> None: ... + def _raise(self) -> None: ... + def destroy(self) -> None: ... + def _set_window_mode(self, mode: str) -> None: ... + @staticmethod + def set_icon(path: str) -> None: ... + def set_window_title(self, title: str) -> None: ... + def get_window_title(self) -> str: ... + +class NavigationToolbar2: + def set_message(self, message: str) -> None: ... + +class Timer: + def _timer_start(self, *args: object) -> None: ... + def _timer_stop(self) -> None: ... diff --git a/lib/matplotlib/ft2font.pyi b/lib/matplotlib/ft2font.pyi index 882cde6c7ae9..b302a9c9aae0 100644 --- a/lib/matplotlib/ft2font.pyi +++ b/lib/matplotlib/ft2font.pyi @@ -244,18 +244,21 @@ class FT2Font(Buffer): def __buffer__(self, flags: int, /) -> memoryview: ... def _layout( self, - text: str, + string: str, flags: LoadFlags, + *, features: tuple[str, ...] | None = ..., language: str | tuple[tuple[str, int, int], ...] | None = ..., ) -> list[LayoutItem]: ... def clear(self) -> None: ... def draw_glyph_to_bitmap( - self, image: NDArray[np.uint8], x: int, y: int, glyph: Glyph, antialiased: bool = ... + self, image: NDArray[np.uint8], x: int, y: int, glyph: Glyph, *, antialiased: bool = ... ) -> None: ... - def draw_glyphs_to_bitmap(self, antialiased: bool = ...) -> None: ... + def draw_glyphs_to_bitmap(self, *, antialiased: bool = ...) -> None: ... def get_bitmap_offset(self) -> tuple[int, int]: ... - def get_char_index(self, codepoint: CharacterCodeType) -> GlyphIndexType: ... + def get_char_index( + self, codepoint: CharacterCodeType, *, _fallback: bool = ... + ) -> GlyphIndexType: ... def get_charmap(self) -> dict[CharacterCodeType, GlyphIndexType]: ... def get_descent(self) -> int: ... def get_glyph_name(self, index: GlyphIndexType) -> str: ... @@ -284,7 +287,7 @@ class FT2Font(Buffer): def get_sfnt_table(self, name: Literal["pclt"]) -> _SfntPcltDict | None: ... def get_width_height(self) -> tuple[int, int]: ... def load_char(self, charcode: CharacterCodeType, flags: LoadFlags = ...) -> Glyph: ... - def load_glyph(self, glyphindex: GlyphIndexType, flags: LoadFlags = ...) -> Glyph: ... + def load_glyph(self, glyph_index: GlyphIndexType, flags: LoadFlags = ...) -> Glyph: ... def select_charmap(self, i: int) -> None: ... def set_charmap(self, i: int) -> None: ... def set_size(self, ptsize: float, dpi: float) -> None: ... @@ -294,7 +297,7 @@ class FT2Font(Buffer): angle: float = ..., flags: LoadFlags = ..., *, - features: tuple[str] | None = ..., + features: tuple[str, ...] | None = ..., language: str | list[tuple[str, int, int]] | None = ..., ) -> NDArray[np.float64]: ... @property diff --git a/lib/matplotlib/image.pyi b/lib/matplotlib/image.pyi index 4c2a8fbdb0e6..3d1d2eb8758c 100644 --- a/lib/matplotlib/image.pyi +++ b/lib/matplotlib/image.pyi @@ -1,7 +1,8 @@ from collections.abc import Callable, Sequence +from enum import Enum import os import pathlib -from typing import Any, BinaryIO, Literal +from typing import Any, BinaryIO, Literal, cast import numpy as np from numpy.typing import ArrayLike, NDArray @@ -19,34 +20,58 @@ from matplotlib.transforms import Affine2D, BboxBase, Bbox, Transform # These names are re-exported from matplotlib._image. # -BESSEL: int -BICUBIC: int -BILINEAR: int -BLACKMAN: int -CATROM: int -GAUSSIAN: int -HAMMING: int -HANNING: int -HERMITE: int -KAISER: int -LANCZOS: int -MITCHELL: int -NEAREST: int -QUADRIC: int -SINC: int -SPLINE16: int -SPLINE36: int +class _InterpolationType(Enum): + NEAREST = cast(int, ...) + BILINEAR = cast(int, ...) + BICUBIC = cast(int, ...) + SPLINE16 = cast(int, ...) + SPLINE36 = cast(int, ...) + HANNING = cast(int, ...) + HAMMING = cast(int, ...) + HERMITE = cast(int, ...) + KAISER = cast(int, ...) + QUADRIC = cast(int, ...) + CATROM = cast(int, ...) + GAUSSIAN = cast(int, ...) + BESSEL = cast(int, ...) + MITCHELL = cast(int, ...) + SINC = cast(int, ...) + LANCZOS = cast(int, ...) + BLACKMAN = cast(int, ...) + +# ``_InterpolationType`` uses ``.export_values()``, so every member is also +# injected as a module-level constant. +NEAREST: _InterpolationType +BILINEAR: _InterpolationType +BICUBIC: _InterpolationType +SPLINE16: _InterpolationType +SPLINE36: _InterpolationType +HANNING: _InterpolationType +HAMMING: _InterpolationType +HERMITE: _InterpolationType +KAISER: _InterpolationType +QUADRIC: _InterpolationType +CATROM: _InterpolationType +GAUSSIAN: _InterpolationType +BESSEL: _InterpolationType +MITCHELL: _InterpolationType +SINC: _InterpolationType +LANCZOS: _InterpolationType +BLACKMAN: _InterpolationType def resample( input_array: NDArray[np.float32] | NDArray[np.float64] | NDArray[np.int8], output_array: NDArray[np.float32] | NDArray[np.float64] | NDArray[np.int8], transform: Transform, - interpolation: int = ..., + interpolation: _InterpolationType = ..., resample: bool = ..., alpha: float = ..., norm: bool = ..., radius: float = ..., ) -> None: ... +def calculate_rms_and_diff( + expected_image: np.ndarray, actual_image: np.ndarray +) -> tuple[float, np.ndarray]: ... # # END names re-exported from matplotlib._image.