Skip to content

Commit 07effe5

Browse files
committed
Change return type
1 parent 292d7f7 commit 07effe5

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ def _make_axes_method(func):
6464
return func
6565

6666

67+
class _GroupedBarReturn:
68+
"""
69+
A provisional result object for `.Axes.grouped_bar`.
70+
71+
This is a placeholder for a future better return type. We try to build in
72+
backward compatibility / migration possibilities.
73+
74+
The only public interfaces are the ``bar_containers`` attribute and the
75+
``remove()`` method.
76+
"""
77+
def __init__(self, bar_containers):
78+
self.bar_containers = bar_containers
79+
80+
def remove(self):
81+
[b.remove() for b in self.bars]
82+
83+
6784
@_docstring.interpd
6885
class Axes(_AxesBase):
6986
"""
@@ -3161,12 +3178,17 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31613178
31623179
Returns
31633180
-------
3164-
list of `.BarContainer`
3165-
The results of the individual `~.Axes.bar` calls for each dataset.
3181+
_GroupedBarReturn
3182+
3183+
A provisional result object. This will be refined in the future.
3184+
For now, the API is limited to
3185+
3186+
- the attribute ``bar_containers``, which is a list of
3187+
`.BarContainer`, i.e. the results of the individual `~.Axes.bar`
3188+
calls for each dataset.
31663189
3167-
.. warning::
3168-
The return type is provisional and will likely be replaced
3169-
by a more convenient object.
3190+
- a ``remove()`` method, that remove all bars from the Axes.
3191+
See also `.Artist.remove()`.
31703192
31713193
"""
31723194
if hasattr(heights, 'keys'):

lib/matplotlib/axes/_axes.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ import numpy as np
4040
from numpy.typing import ArrayLike
4141
from matplotlib.typing import ColorType, MarkerType, LineStyleType
4242

43+
44+
class _GroupedBarReturn:
45+
def __init__(self, bar_containers: list[BarContainer]) -> None: ...
46+
def remove(self) -> None: ...
47+
4348
class Axes(_AxesBase):
4449
def get_title(self, loc: Literal["left", "center", "right"] = ...) -> str: ...
4550
def set_title(

0 commit comments

Comments
 (0)