@@ -3077,18 +3077,14 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
3077
3077
This function is new in v3.11, and the API is still provisional.
3078
3078
We may still fine-tune some aspects based on user-feedback.
3079
3079
3080
- This is a convenience function to plot bars for multiple datasets.
3081
- In particular, it simplifies positioning of the bars compared to individual
3082
- `~.Axes.bar` plots.
3083
-
3084
3080
Bar plots present categorical data as a sequence of bars, one bar per category.
3085
- We call one set of such values a *dataset* and it's bars all share the same
3081
+ We call one set of such values a *dataset* and its bars all share the same
3086
3082
color. Grouped bar plots show multiple such datasets, where the values per
3087
3083
category are grouped together. The category names are drawn as tick labels
3088
3084
below the bar groups. Each dataset has a distinct bar color, and can optionally
3089
3085
get a label that is used for the legend.
3090
3086
3091
- Here is an example call structure and the corresponding plot :
3087
+ Example :
3092
3088
3093
3089
.. code-block:: python
3094
3090
@@ -3098,6 +3094,10 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
3098
3094
3099
3095
.. plot:: _embedded_plots/grouped_bar.py
3100
3096
3097
+ ``grouped_bar()`` is a high-level plotting function for grouped bar charts.
3098
+ Use `~.Axes.bar` instead if you need finer grained control on individual bar
3099
+ positions or widths.
3100
+
3101
3101
Parameters
3102
3102
----------
3103
3103
heights : list of array-like or dict of array-like or 2D array \
@@ -3121,9 +3121,6 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
3121
3121
- dict of array-like: A mapping from names to datasets. Each dataset
3122
3122
(dict value) must have the same number of elements.
3123
3123
3124
- This is similar to passing a list of array-like, with the addition that
3125
- each dataset gets a name.
3126
-
3127
3124
Example call:
3128
3125
3129
3126
.. code-block:: python
@@ -3154,21 +3151,16 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
3154
3151
3155
3152
.. code-block:: python
3156
3153
3157
- group_labels = ["group_A ", "group_B "]
3154
+ categories = ["A ", "B "]
3158
3155
dataset_labels = ["dataset_0", "dataset_1", "dataset_2"]
3159
3156
array = np.random.random((2, 3))
3160
-
3161
- Note that this is consistent with pandas. These two calls produce
3162
- the same bar plot structure:
3163
-
3164
- .. code-block:: python
3165
-
3166
3157
grouped_bar(array, tick_labels=categories, labels=dataset_labels)
3167
- df = pd.DataFrame(array, index=categories, columns=dataset_labels)
3168
- df.plot.bar()
3169
3158
3170
3159
- a `pandas.DataFrame`.
3171
3160
3161
+ The index is used for the categories, the columns are used for the
3162
+ datasets.
3163
+
3172
3164
.. code-block:: python
3173
3165
3174
3166
df = pd.DataFrame(
@@ -3178,6 +3170,9 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
3178
3170
)
3179
3171
grouped_bar(df)
3180
3172
3173
+ # is equivalent to
3174
+ grouped_bar(df.to_numpy(), tick_labels=df.index, labels=df.columns)
3175
+
3181
3176
Note that ``grouped_bar(df)`` produces a structurally equivalent plot like
3182
3177
``df.plot.bar()``.
3183
3178
@@ -3187,9 +3182,8 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
3187
3182
3188
3183
tick_labels : list of str, optional
3189
3184
The category labels, which are placed on ticks at the center *positions*
3190
- of the bar groups.
3191
-
3192
- If not set, the axis ticks (positions and labels) are left unchanged.
3185
+ of the bar groups. If not set, the axis ticks (positions and labels) are
3186
+ left unchanged.
3193
3187
3194
3188
labels : list of str, optional
3195
3189
The labels of the datasets, i.e. the bars within one group.
0 commit comments