Skip to content

Commit b62f516

Browse files
committed
Rename dataset_labels -> labels
1 parent 14a8097 commit b62f516

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

galleries/examples/lines_bars_and_markers/grouped_bar_chart.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# grouped_bar() with list of datasets
3636
# note also that this is a straight-forward generalization of the single-dataset case:
3737
# bar(x, data1, label="data1")
38-
axs[1].grouped_bar(x, [data1, data2, data3], dataset_labels=["data1", "data2", "data3"])
38+
axs[1].grouped_bar(x, [data1, data2, data3], labels=["data1", "data2", "data3"])
3939

4040

4141
# %%
@@ -57,7 +57,7 @@
5757
fig, axs = plt.subplots(1, 2)
5858

5959
# explicitly extract values and labels from a dict and feed to grouped_bar():
60-
axs[0].grouped_bar(x, datasets.values(), dataset_labels=datasets.keys())
60+
axs[0].grouped_bar(x, datasets.values(), labels=datasets.keys())
6161
# accepting a dict as input
6262
axs[1].grouped_bar(x, datasets)
6363

@@ -94,7 +94,7 @@
9494
columns = ["data1", "data2", "data3"]
9595

9696
fig, ax = plt.subplots()
97-
ax.grouped_bar(x, data, dataset_labels=columns)
97+
ax.grouped_bar(x, data, labels=columns)
9898

9999
# %%
100100
# This creates the same plot as pandas (code cannot be executed because pandas

lib/matplotlib/axes/_axes.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,7 @@ def broken_barh(self, xranges, yrange, **kwargs):
30493049
return col
30503050

30513051
def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
3052-
dataset_labels=None, orientation="vertical", colors=None,
3052+
labels=None, orientation="vertical", colors=None,
30533053
**kwargs):
30543054
"""
30553055
Make a grouped bar plot.
@@ -3119,8 +3119,12 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31193119
bar_spacing : float
31203120
The space between bars in units of bar width.
31213121
3122-
dataset_labels : array-like of str, optional
3123-
The labels of the datasets.
3122+
labels : array-like of str, optional
3123+
The labels of the datasets, i.e. the bars within one group.
3124+
These will show up in the legend.
3125+
3126+
Note: The "other" label dimension are the group labels, which
3127+
can be set via *x*.
31243128
31253129
orientation : {"vertical", "horizontal"}, default: vertical
31263130
@@ -3138,10 +3142,10 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31383142
31393143
"""
31403144
if hasattr(heights, 'keys'):
3141-
if dataset_labels is not None:
3145+
if labels is not None:
31423146
raise ValueError(
3143-
"'dataset_labels' cannot be used if 'heights' are a mapping")
3144-
dataset_labels = heights.keys()
3147+
"'labels' cannot be used if 'heights' are a mapping")
3148+
labels = heights.keys()
31453149
heights = heights.values()
31463150
elif hasattr(heights, 'shape'):
31473151
heights = heights.T
@@ -3185,23 +3189,23 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31853189
bar_spacing_abs = bar_spacing * bar_width
31863190
margin_abs = 0.5 * group_spacing * bar_width
31873191

3188-
if dataset_labels is None:
3189-
dataset_labels = [None] * num_datasets
3192+
if labels is None:
3193+
labels = [None] * num_datasets
31903194
else:
3191-
assert len(dataset_labels) == num_datasets
3195+
assert len(labels) == num_datasets
31923196

31933197
# place the bars, but only use numerical positions, categorical tick labels
31943198
# are handled separately below
3195-
for i, (hs, dataset_label, color) in enumerate(
3196-
zip(heights, dataset_labels, colors)):
3199+
for i, (hs, label, color) in enumerate(
3200+
zip(heights, labels, colors)):
31973201
lefts = (group_centers - 0.5 * group_distance + margin_abs
31983202
+ i * (bar_width + bar_spacing_abs))
31993203
if orientation == "vertical":
32003204
self.bar(lefts, hs, width=bar_width, align="edge",
3201-
label=dataset_label, color=color, **kwargs)
3205+
label=label, color=color, **kwargs)
32023206
else:
32033207
self.barh(lefts, hs, height=bar_width, align="edge",
3204-
label=dataset_label, color=color, **kwargs)
3208+
label=label, color=color, **kwargs)
32053209

32063210
if tick_labels is not None:
32073211
if orientation == "vertical":

lib/matplotlib/axes/_axes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class Axes(_AxesBase):
286286
*,
287287
group_spacing : float | None = ...,
288288
bar_spacing : float | None = ...,
289-
dataset_labels : Sequence[str] | None = ...,
289+
labels : Sequence[str] | None = ...,
290290
orientation: Literal["vertical", "horizontal"] = ...,
291291
colors: Iterable[ColorType] | None = ...,
292292
**kwargs

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,7 +3396,7 @@ def grouped_bar(
33963396
*,
33973397
group_spacing: float | None = 1.5,
33983398
bar_spacing: float | None = 0,
3399-
dataset_labels: Sequence[str] | None = None,
3399+
labels: Sequence[str] | None = None,
34003400
orientation: Literal["vertical", "horizontal"] = "vertical",
34013401
colors: Iterable[ColorType] | None = None,
34023402
**kwargs,
@@ -3406,7 +3406,7 @@ def grouped_bar(
34063406
heights,
34073407
group_spacing=group_spacing,
34083408
bar_spacing=bar_spacing,
3409-
dataset_labels=dataset_labels,
3409+
labels=labels,
34103410
orientation=orientation,
34113411
colors=colors,
34123412
**kwargs,

0 commit comments

Comments
 (0)