@@ -3048,6 +3048,7 @@ def broken_barh(self, xranges, yrange, **kwargs):
30483048
30493049 return col
30503050
3051+ @_docstring .interpd
30513052 def grouped_bar (self , x , heights , * , group_spacing = 1.5 , bar_spacing = 0 ,
30523053 labels = None , orientation = "vertical" , colors = None ,
30533054 ** kwargs ):
@@ -3058,6 +3059,10 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
30583059 This function is new in v3.10, and the API is still provisional.
30593060 We may still fine-tune some aspects based on user-feedback.
30603061
3062+ This is a convenience function to plot bar charts for multiple datasets
3063+ into one Axes. In particular, it simplifies positioning of the bars
3064+ compared to individual `~.Axes.bar` plots.
3065+
30613066 Parameters
30623067 ----------
30633068 x : array-like or list of str
@@ -3074,44 +3079,57 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
30743079
30753080 .. code-block:: none
30763081
3077- x = ['a', 'b']
3078- group_labels = ['ds0', 'ds1', 'ds2']
3082+ x = ["a", "b"]
3083+
3084+ # x[0] x[1]
3085+ dataset_0 = [ds0_a, ds0_b]
3086+ dataset_1 = [ds1_a, ds1_b]
3087+ dataset_2 = [ds2_a, ds2_b]
3088+
3089+ heights = [dataset_0, dataset_1, dataset_2]
3090+
3091+ Example call::
3092+
3093+ grouped_bar(x, [dataset_0, dataset_1, dataset_2])
3094+
3095+ - dict of array-like: A mapping names to datasets. Each dataset
3096+ (dict value) must have ``len(x)`` elements.
30793097
3080- # group_labels: ds0 ds1 dw2
3081- heights = [dataset_0, dataset_1, dataset_2]
3098+ This is similar to passing a list of array-like, with the addition that
3099+ each dataset gets a name.
30823100
3083- # x[0] x[1]
3084- dataset_0 = [ds0_a, ds0_b]
3101+ Example call::
30853102
3086- # x[0] x[1]
3087- heights = [[ds0_a, ds0_b], # dataset_0
3088- [ds1_a, ds1_b], # dataset_1
3089- [ds2_a, ds2_b], # dataset_2
3090- ]
3103+ grouped_bar(x, {'ds0': dataset_0, 'ds1': dataset_1, 'ds2': dataset_2]})
30913104
3092- - dict of array-like: A names to datasets, each dataset (dict value)
3093- must have ``len(x)`` elements.
3105+ The names are used as *labels*, i.e. the following two calls are
3106+ equivalent::
30943107
3095- group_labels = heights.keys()
3096- heights = heights.values()
3108+ data_dict = {'ds0': dataset_0, 'ds1': dataset_1, 'ds2': dataset_2]}
3109+ grouped_bar(x, data_dict)
3110+ grouped_bar(x, data_dict.values(), labels=data_dict.keys())
30973111
3098- - a 2D array: columns map to *x*, columns are the different datasets.
3112+ When using a dict-like input, you must not pass *labels* explicitly.
3113+
3114+ - a 2D array: The columns are the different datasets.
30993115
31003116 .. code-block:: none
31013117
31023118 dataset_0 dataset_1 dataset_2
3103- x[0]='a' ds0_a ds1_a ds2_a
3104- x[1]='b' ds0_b ds1_b ds2_b
3119+ x[0]="a" ds0_a ds1_a ds2_a
3120+ x[1]="b" ds0_b ds1_b ds2_b
31053121
3106- Note that this is consistent with pandas. These two calls produce
3107- the same bar plot structure::
3122+ .. code-block::
31083123
3109- grouped_bar(x, array, group_labels=group_labels)
3110- pd.DataFrame(array, index=x, columns=group_labels).plot.bar()
3124+ x = ["a", "b"]
3125+ dataset_labels = ["dataset_0", "dataset_1", "dataset_2"]
3126+ array = np.random.random((2, 3))
31113127
3128+ Note that this is consistent with pandas. These two calls produce
3129+ the same bar plot structure::
31123130
3113- An iterable of array-like: The iteration runs over the groups.
3114- Each individual array-like is the list of label values for that group.
3131+ grouped_bar(x, array, labels=dataset_labels)
3132+ pd.DataFrame(array, index=x, columns=dataset_labels).plot.bar()
31153133
31163134 group_spacing : float
31173135 The space between two bar groups in units of bar width.
@@ -3126,7 +3144,8 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31263144 Note: The "other" label dimension are the group labels, which
31273145 can be set via *x*.
31283146
3129- orientation : {"vertical", "horizontal"}, default: vertical
3147+ orientation : {"vertical", "horizontal"}, default: "vertical"
3148+ The direction of the bars.
31303149
31313150 colors : list of :mpltype:`color`, optional
31323151 A sequence of colors to be cycled through and used to color bars
@@ -3142,7 +3161,12 @@ def grouped_bar(self, x, heights, *, group_spacing=1.5, bar_spacing=0,
31423161
31433162 Returns
31443163 -------
3145- A list of `.BarContainer` instances, one for each dataset.
3164+ list of `.BarContainer`
3165+ The results of the individual `~.Axes.bar` calls for each dataset.
3166+
3167+ .. warning::
3168+ The return type is provisional and will likely be replaced
3169+ by a more convenient object.
31463170
31473171 """
31483172 if hasattr (heights , 'keys' ):
0 commit comments