Skip to content

Commit

Permalink
Change return type
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm committed Dec 18, 2024
1 parent 292d7f7 commit 07effe5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
32 changes: 27 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ def _make_axes_method(func):
return func


class _GroupedBarReturn:
"""
A provisional result object for `.Axes.grouped_bar`.
This is a placeholder for a future better return type. We try to build in
backward compatibility / migration possibilities.
The only public interfaces are the ``bar_containers`` attribute and the
``remove()`` method.
"""
def __init__(self, bar_containers):
self.bar_containers = bar_containers

def remove(self):
[b.remove() for b in self.bars]


@_docstring.interpd
class Axes(_AxesBase):
"""
Expand Down Expand Up @@ -3161,12 +3178,17 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
Returns
-------
list of `.BarContainer`
The results of the individual `~.Axes.bar` calls for each dataset.
_GroupedBarReturn
A provisional result object. This will be refined in the future.
For now, the API is limited to
- the attribute ``bar_containers``, which is a list of
`.BarContainer`, i.e. the results of the individual `~.Axes.bar`
calls for each dataset.
.. warning::
The return type is provisional and will likely be replaced
by a more convenient object.
- a ``remove()`` method, that remove all bars from the Axes.
See also `.Artist.remove()`.
"""
if hasattr(heights, 'keys'):
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ import numpy as np
from numpy.typing import ArrayLike
from matplotlib.typing import ColorType, MarkerType, LineStyleType


class _GroupedBarReturn:
def __init__(self, bar_containers: list[BarContainer]) -> None: ...
def remove(self) -> None: ...

class Axes(_AxesBase):
def get_title(self, loc: Literal["left", "center", "right"] = ...) -> str: ...
def set_title(
Expand Down

0 comments on commit 07effe5

Please sign in to comment.