From 71de0a9a0f7547bfb4c73fd9d5cb11d5f18278d7 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 20 Aug 2025 07:35:06 +0100 Subject: [PATCH] Backport PR #30412: {Check,Radio}Buttons: Improve docs of label_props --- lib/matplotlib/widgets.py | 20 ++++++++++++++------ lib/matplotlib/widgets.pyi | 8 ++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 9c676574310c..631ada38027a 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -1010,8 +1010,11 @@ def __init__(self, ax, labels, actives=None, *, useblit=True, .. versionadded:: 3.7 - label_props : dict, optional - Dictionary of `.Text` properties to be used for the labels. + label_props : dict of lists, optional + Dictionary of `.Text` properties to be used for the labels. Each + dictionary value should be a list of at least a single element. If + the list is of length M, its values are cycled such that the Nth + label gets the (N mod M) property. .. versionadded:: 3.7 frame_props : dict, optional @@ -1111,7 +1114,8 @@ def set_label_props(self, props): Parameters ---------- props : dict - Dictionary of `.Text` properties to be used for the labels. + Dictionary of `.Text` properties to be used for the labels. Same + format as label_props argument of :class:`CheckButtons`. """ _api.check_isinstance(dict, props=props) props = _expand_text_props(props) @@ -1579,8 +1583,11 @@ def __init__(self, ax, labels, active=0, activecolor=None, *, .. versionadded:: 3.7 - label_props : dict or list of dict, optional - Dictionary of `.Text` properties to be used for the labels. + label_props : dict of lists, optional + Dictionary of `.Text` properties to be used for the labels. Each + dictionary value should be a list of at least a single element. If + the list is of length M, its values are cycled such that the Nth + label gets the (N mod M) property. .. versionadded:: 3.7 radio_props : dict, optional @@ -1689,7 +1696,8 @@ def set_label_props(self, props): Parameters ---------- props : dict - Dictionary of `.Text` properties to be used for the labels. + Dictionary of `.Text` properties to be used for the labels. Same + format as label_props argument of :class:`RadioButtons`. """ _api.check_isinstance(dict, props=props) props = _expand_text_props(props) diff --git a/lib/matplotlib/widgets.pyi b/lib/matplotlib/widgets.pyi index 0fcd1990e17e..ae88fbc5111f 100644 --- a/lib/matplotlib/widgets.pyi +++ b/lib/matplotlib/widgets.pyi @@ -154,11 +154,11 @@ class CheckButtons(AxesWidget): actives: Iterable[bool] | None = ..., *, useblit: bool = ..., - label_props: dict[str, Any] | None = ..., + label_props: dict[str, Sequence[Any]] | None = ..., frame_props: dict[str, Any] | None = ..., check_props: dict[str, Any] | None = ..., ) -> None: ... - def set_label_props(self, props: dict[str, Any]) -> None: ... + def set_label_props(self, props: dict[str, Sequence[Any]]) -> None: ... def set_frame_props(self, props: dict[str, Any]) -> None: ... def set_check_props(self, props: dict[str, Any]) -> None: ... def set_active(self, index: int, state: bool | None = ...) -> None: ... # type: ignore[override] @@ -208,10 +208,10 @@ class RadioButtons(AxesWidget): activecolor: ColorType | None = ..., *, useblit: bool = ..., - label_props: dict[str, Any] | Sequence[dict[str, Any]] | None = ..., + label_props: dict[str, Sequence[Any]] | None = ..., radio_props: dict[str, Any] | None = ..., ) -> None: ... - def set_label_props(self, props: dict[str, Any]) -> None: ... + def set_label_props(self, props: dict[str, Sequence[Any]]) -> None: ... def set_radio_props(self, props: dict[str, Any]) -> None: ... def set_active(self, index: int) -> None: ... def clear(self) -> None: ...