From e4f2ed47d577ef1b1e226c65f7af4365244e732c Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 31 Aug 2023 09:43:32 +0200 Subject: [PATCH] Backport PR #26656: TYP: Fix some small bugs --- lib/matplotlib/_pylab_helpers.pyi | 6 ++++-- lib/matplotlib/axes/_axes.py | 7 +++++-- lib/matplotlib/axes/_axes.pyi | 12 ++++++------ lib/matplotlib/legend.py | 4 ++-- lib/matplotlib/legend.pyi | 2 +- lib/matplotlib/pyplot.py | 10 +++++----- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/matplotlib/_pylab_helpers.pyi b/lib/matplotlib/_pylab_helpers.pyi index 6e1c8889833f..bdd8cfba3173 100644 --- a/lib/matplotlib/_pylab_helpers.pyi +++ b/lib/matplotlib/_pylab_helpers.pyi @@ -6,7 +6,7 @@ from matplotlib.figure import Figure class Gcf: figs: OrderedDict[int, FigureManagerBase] @classmethod - def get_fig_manager(cls, num: int) -> FigureManagerBase: ... + def get_fig_manager(cls, num: int) -> FigureManagerBase | None: ... @classmethod def destroy(cls, num: int | FigureManagerBase) -> None: ... @classmethod @@ -20,7 +20,9 @@ class Gcf: @classmethod def get_num_fig_managers(cls) -> int: ... @classmethod - def get_active(cls) -> FigureManagerBase: ... + def get_active(cls) -> FigureManagerBase | None: ... + @classmethod + def _set_new_active_manager(cls, manager: FigureManagerBase) -> None: ... @classmethod def set_active(cls, manager: FigureManagerBase) -> None: ... @classmethod diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 4d5907503f09..c1ad5956e2cb 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -280,7 +280,7 @@ def legend(self, *args, **kwargs): Parameters ---------- - handles : sequence of `.Artist`, optional + handles : sequence of (`.Artist` or tuple of `.Artist`), optional A list of Artists (lines, patches) to be added to the legend. Use this together with *labels*, if you need full control on what is shown in the legend and the automatic mechanism described above @@ -289,6 +289,9 @@ def legend(self, *args, **kwargs): The length of handles and labels should be the same in this case. If they are not, they are truncated to the smaller length. + If an entry contains a tuple, then the legend handler for all Artists in the + tuple will be placed alongside a single label. + labels : list of str, optional A list of labels to show next to the artists. Use this together with *handles*, if you need full control on what @@ -3436,7 +3439,7 @@ def errorbar(self, x, y, yerr=None, xerr=None, If True, will plot the errorbars above the plot symbols. Default is below. - lolims, uplims, xlolims, xuplims : bool, default: False + lolims, uplims, xlolims, xuplims : bool or array-like, default: False These arguments can be used to indicate that a value gives only upper/lower limits. In that case a caret symbol is used to indicate this. *lims*-arguments may be scalars, or array-likes of diff --git a/lib/matplotlib/axes/_axes.pyi b/lib/matplotlib/axes/_axes.pyi index 30c0622b89f5..96ea087f7eb9 100644 --- a/lib/matplotlib/axes/_axes.pyi +++ b/lib/matplotlib/axes/_axes.pyi @@ -57,9 +57,9 @@ class Axes(_AxesBase): @overload def legend(self) -> Legend: ... @overload - def legend(self, handles: Sequence[Artist], labels: Sequence[str], **kwargs) -> Legend: ... + def legend(self, handles: Sequence[Artist | tuple[Artist, ...]], labels: Sequence[str], **kwargs) -> Legend: ... @overload - def legend(self, *, handles: Sequence[Artist], **kwargs) -> Legend: ... + def legend(self, *, handles: Sequence[Artist | tuple[Artist, ...]], **kwargs) -> Legend: ... @overload def legend(self, labels: Sequence[str], **kwargs) -> Legend: ... @overload @@ -332,10 +332,10 @@ class Axes(_AxesBase): elinewidth: float | None = ..., capsize: float | None = ..., barsabove: bool = ..., - lolims: bool = ..., - uplims: bool = ..., - xlolims: bool = ..., - xuplims: bool = ..., + lolims: bool | ArrayLike = ..., + uplims: bool | ArrayLike = ..., + xlolims: bool | ArrayLike = ..., + xuplims: bool | ArrayLike = ..., errorevery: int | tuple[int, int] = ..., capthick: float | None = ..., *, diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 18bb7242e34e..7ed8e5a4448f 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -401,7 +401,7 @@ def __init__( parent : `~matplotlib.axes.Axes` or `.Figure` The artist that contains the legend. - handles : list of `.Artist` + handles : list of (`.Artist` or tuple of `.Artist`) A list of Artists (lines, patches) to be added to the legend. labels : list of str @@ -1330,7 +1330,7 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs): Returns ------- - handles : list of `.Artist` + handles : list of (`.Artist` or tuple of `.Artist`) The legend handles. labels : list of str The legend labels. diff --git a/lib/matplotlib/legend.pyi b/lib/matplotlib/legend.pyi index 077aaf672d39..d559b06c5d5d 100644 --- a/lib/matplotlib/legend.pyi +++ b/lib/matplotlib/legend.pyi @@ -52,7 +52,7 @@ class Legend(Artist): def __init__( self, parent: Axes | Figure, - handles: Iterable[Artist], + handles: Iterable[Artist | tuple[Artist, ...]], labels: Iterable[str], *, loc: str | tuple[float, float] | int | None = ..., diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 04fdcbc744c9..976e997a472b 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -938,7 +938,7 @@ def figure( for hookspecs in rcParams["figure.hooks"]: module_name, dotted_name = hookspecs.split(":") - obj = importlib.import_module(module_name) + obj: Any = importlib.import_module(module_name) for part in dotted_name.split("."): obj = getattr(obj, part) obj(fig) @@ -2961,10 +2961,10 @@ def errorbar( elinewidth: float | None = None, capsize: float | None = None, barsabove: bool = False, - lolims: bool = False, - uplims: bool = False, - xlolims: bool = False, - xuplims: bool = False, + lolims: bool | ArrayLike = False, + uplims: bool | ArrayLike = False, + xlolims: bool | ArrayLike = False, + xuplims: bool | ArrayLike = False, errorevery: int | tuple[int, int] = 1, capthick: float | None = None, *, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy