@@ -3148,6 +3148,20 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
31483148 df = pd.DataFrame(array, index=group_labels, columns=dataset_labels)
31493149 df.plot.bar()
31503150
3151+ - a `pandas.DataFrame`.
3152+
3153+ .. code-block::
3154+
3155+ df = pd.DataFrame(
3156+ np.random.random((2, 3))
3157+ index=["group_A", "group_B"],
3158+ columns=["dataset_0", "dataset_1", "dataset_2"]
3159+ )
3160+ grouped_bar(df)
3161+
3162+ Note that ``grouped_bar(df)`` produced a structurally equivalent plot like
3163+ ``df.plot.bar()`.
3164+
31513165 positions : array-like, optional
31523166 The center positions of the bar groups. The values have to be equidistant.
31533167 If not given, a sequence of integer positions 0, 1, 2, ... is used.
@@ -3198,13 +3212,19 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
31983212 See also `.Artist.remove()`.
31993213
32003214 """
3201- if hasattr (heights , 'keys' ):
3215+ if cbook ._is_pandas_dataframe (heights ):
3216+ if labels is None :
3217+ labels = heights .columns .tolist ()
3218+ if tick_labels is None :
3219+ tick_labels = heights .index .tolist ()
3220+ heights = heights .to_numpy ().T
3221+ elif hasattr (heights , 'keys' ): # dict
32023222 if labels is not None :
32033223 raise ValueError (
32043224 "'labels' cannot be used if 'heights' are a mapping" )
32053225 labels = heights .keys ()
32063226 heights = list (heights .values ())
3207- elif hasattr (heights , 'shape' ):
3227+ elif hasattr (heights , 'shape' ): # numpy array
32083228 heights = heights .T
32093229
32103230 num_datasets = len (heights )
0 commit comments