Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e7b2da6

Browse filesBrowse files
committed
Return a list of BarContainer
1 parent b0dd13b commit e7b2da6
Copy full SHA for e7b2da6

File tree

Expand file treeCollapse file tree

3 files changed

+14
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-8
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,6 +3105,10 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31053105
31063106
%(Rectangle:kwdoc)s
31073107
3108+
Returns
3109+
-------
3110+
A list of `.BarContainer` instances, one for each dataset.
3111+
31083112
"""
31093113
if hasattr(heights, 'keys'):
31103114
if labels is not None:
@@ -3161,24 +3165,26 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31613165

31623166
# place the bars, but only use numerical positions, categorical tick labels
31633167
# are handled separately below
3168+
result = []
31643169
for i, (hs, label, color) in enumerate(
31653170
zip(heights, labels, colors)):
31663171
lefts = (group_centers - 0.5 * group_distance + margin_abs
31673172
+ i * (bar_width + bar_spacing_abs))
31683173
if orientation == "vertical":
3169-
self.bar(lefts, hs, width=bar_width, align="edge",
3170-
label=label, color=color, **kwargs)
3174+
bc = self.bar(lefts, hs, width=bar_width, align="edge",
3175+
label=label, color=color, **kwargs)
31713176
else:
3172-
self.barh(lefts, hs, height=bar_width, align="edge",
3173-
label=label, color=color, **kwargs)
3177+
bc = self.barh(lefts, hs, height=bar_width, align="edge",
3178+
label=label, color=color, **kwargs)
3179+
result.append(bc)
31743180

31753181
if tick_labels is not None:
31763182
if orientation == "vertical":
31773183
self.xaxis.set_ticks(group_centers, labels=tick_labels)
31783184
else:
31793185
self.yaxis.set_ticks(group_centers, labels=tick_labels)
31803186

3181-
# TODO: does not return anything for now
3187+
return result
31823188

31833189
@_preprocess_data()
31843190
def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,

‎lib/matplotlib/axes/_axes.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.pyi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class Axes(_AxesBase):
295295
orientation: Literal["vertical", "horizontal"] = ...,
296296
colors: Iterable[ColorType] | None = ...,
297297
**kwargs
298-
) -> None: ...
298+
) -> list[BarContainer]: ...
299299
def stem(
300300
self,
301301
*args: ArrayLike | str,

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,8 +3388,8 @@ def grouped_bar(
33883388
orientation: Literal["vertical", "horizontal"] = "vertical",
33893389
colors: Iterable[ColorType] | None = None,
33903390
**kwargs,
3391-
) -> None:
3392-
gca().grouped_bar(
3391+
) -> list[BarContainer]:
3392+
return gca().grouped_bar(
33933393
x,
33943394
heights,
33953395
group_spacing=group_spacing,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.