Skip to content

Commit 214591f

Browse files
committed
More concise terminology and description of the supported input data formats.
1 parent df4c389 commit 214591f

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

doc/_embedded_plots/grouped_bar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import matplotlib.pyplot as plt
22

3-
group_labels = ['group A', 'group B']
3+
categories = ['A', 'B']
44
data0 = [1.0, 3.0]
55
data1 = [1.4, 3.4]
66
data2 = [1.8, 3.8]
77

88
fig, ax = plt.subplots(figsize=(4, 2.2))
99
ax.grouped_bar(
1010
[data0, data1, data2],
11-
tick_labels=group_labels,
11+
tick_labels=categories,
1212
labels=['dataset 0', 'dataset 1', 'dataset 2'],
1313
colors=['#1f77b4', '#58a1cf', '#abd0e6'],
1414
)

lib/matplotlib/axes/_axes.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,10 +3080,20 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
30803080
into one Axes. In particular, it simplifies positioning of the bars
30813081
compared to individual `~.Axes.bar` plots.
30823082
3083-
Terminology: A bar *group* is a set of bars drawn next to each other. They
3084-
can be associated with a group name, which is visualized as the tick label
3085-
below that group. A *dataset* is a set of values, one for each bar group.
3086-
This means *dataset_0* will be rendered as the first bar in each bar group.
3083+
Bar plots present categorical data as a sequence of bars, one bar per category.
3084+
We call one set of such values a *dataset* and it's bars all share the same
3085+
color. Grouped bar plots show multiple such datasets, where the values per
3086+
category are grouped together. The category name is drawn as a tick label
3087+
below the bar group. Each dataset has a distinct bar color, and can optionally
3088+
get a label that is used for the legend.
3089+
3090+
The following plot is generated from the code
3091+
3092+
.. code-block:: python
3093+
3094+
grouped_bar([dataset_1, dataset_2, dataset_3],
3095+
tick_labels=['A', 'B'],
3096+
labels=['dataset 1', 'dataset 2', 'dataset 3'])
30873097
30883098
.. plot:: _embedded_plots/grouped_bar.py
30893099
@@ -3097,60 +3107,69 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
30973107
30983108
.. code-block:: none
30993109
3100-
# group_A group_B
3101-
dataset_0 = [ds0_a, ds0_b]
3102-
dataset_1 = [ds1_a, ds1_b]
3103-
dataset_2 = [ds2_a, ds2_b]
3110+
# category_A, category_B
3111+
dataset_0 = [ds0_A, ds0_B]
3112+
dataset_1 = [ds1_A, ds1_B]
3113+
dataset_2 = [ds2_A, ds2_B]
31043114
31053115
heights = [dataset_0, dataset_1, dataset_2]
31063116
31073117
Example call::
31083118
31093119
grouped_bar([dataset_0, dataset_1, dataset_2])
31103120
3111-
- dict of array-like: A mapping names to datasets. Each dataset
3112-
(dict value) must have the same number of elements elements.
3121+
- dict of array-like: A mapping from names to datasets. Each dataset
3122+
(dict value) must have the same number of elements.
31133123
31143124
This is similar to passing a list of array-like, with the addition that
31153125
each dataset gets a name.
31163126
3117-
Example call::
3127+
Example call:
3128+
3129+
.. code-block:: python
31183130
31193131
grouped_bar({'ds0': dataset_0, 'ds1': dataset_1, 'ds2': dataset_2]})
31203132
31213133
The names are used as *labels*, i.e. the following two calls are
3122-
equivalent::
3134+
equivalent:
3135+
3136+
.. code-block:: python
31233137
31243138
data_dict = {'ds0': dataset_0, 'ds1': dataset_1, 'ds2': dataset_2]}
31253139
grouped_bar(data_dict)
31263140
grouped_bar(data_dict.values(), labels=data_dict.keys())
31273141
31283142
When using a dict-like input, you must not pass *labels* explicitly.
31293143
3130-
- a 2D array: The columns are the different datasets.
3144+
- a 2D array: The rows are the categories, the columns are the different
3145+
datasets.
31313146
31323147
.. code-block:: none
31333148
3134-
dataset_0 dataset_1 dataset_2
3135-
group_A ds0_a ds1_a ds2_a
3136-
group_B ds0_b ds1_b ds2_b
3149+
dataset_0 dataset_1 dataset_2
3150+
category_A ds0_a ds1_a ds2_a
3151+
category_B ds0_b ds1_b ds2_b
31373152
3138-
.. code-block::
3153+
Example call:
3154+
3155+
.. code-block:: python
31393156
31403157
group_labels = ["group_A", "group_B"]
31413158
dataset_labels = ["dataset_0", "dataset_1", "dataset_2"]
31423159
array = np.random.random((2, 3))
31433160
31443161
Note that this is consistent with pandas. These two calls produce
3145-
the same bar plot structure::
3162+
the same bar plot structure:
3163+
3164+
.. code-block:: python
31463165
3147-
grouped_bar(array, tick_labels=group_labels, labels=dataset_labels)
3148-
df = pd.DataFrame(array, index=group_labels, columns=dataset_labels)
3166+
grouped_bar(array, tick_labels=categories, labels=dataset_labels)
3167+
df = pd.DataFrame(array, index=categories, columns=dataset_labels)
31493168
df.plot.bar()
31503169
31513170
- a `pandas.DataFrame`.
31523171
3153-
.. code-block::
3172+
.. code-block:: python
31543173
31553174
df = pd.DataFrame(
31563175
np.random.random((2, 3))
@@ -3159,15 +3178,15 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
31593178
)
31603179
grouped_bar(df)
31613180
3162-
Note that ``grouped_bar(df)`` produced a structurally equivalent plot like
3181+
Note that ``grouped_bar(df)`` produces a structurally equivalent plot like
31633182
``df.plot.bar()`.
31643183
31653184
positions : array-like, optional
31663185
The center positions of the bar groups. The values have to be equidistant.
31673186
If not given, a sequence of integer positions 0, 1, 2, ... is used.
31683187
31693188
tick_labels: list of str, optional
3170-
The group labels, which are placed on ticks at the center *positions*
3189+
The category labels, which are placed on ticks at the center *positions*
31713190
of the bar groups.
31723191
31733192
If not set, the axis ticks (positions and labels) are left unchanged.

0 commit comments

Comments
 (0)