Make a grouped bar plot. .. versionadded:: 3.11 The API is still provisional. We may still fine-tune some aspects based on user-feedback. Grouped bar charts visualize a collection of categorical datasets. Each value in a dataset belongs to
(self, heights, *, positions=None, group_spacing=1.5, bar_spacing=0,
tick_labels=None, labels=None, orientation="vertical", colors=None,
**kwargs)
| 3058 | |
| 3059 | @_docstring.interpd |
| 3060 | def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing=0, |
| 3061 | tick_labels=None, labels=None, orientation="vertical", colors=None, |
| 3062 | **kwargs): |
| 3063 | """ |
| 3064 | Make a grouped bar plot. |
| 3065 | |
| 3066 | .. versionadded:: 3.11 |
| 3067 | |
| 3068 | The API is still provisional. We may still fine-tune some aspects based on |
| 3069 | user-feedback. |
| 3070 | |
| 3071 | Grouped bar charts visualize a collection of categorical datasets. Each value |
| 3072 | in a dataset belongs to a distinct category and these categories are the same |
| 3073 | across all datasets. The categories typically have string names, but could |
| 3074 | also be dates or index keys. The values in each dataset are represented by a |
| 3075 | sequence of bars of the same color. The bars of all datasets are grouped |
| 3076 | together by their shared categories. The category names are drawn as the tick |
| 3077 | labels for each bar group. Each dataset has a distinct bar color, and can |
| 3078 | optionally get a label that is used for the legend. |
| 3079 | |
| 3080 | Example: |
| 3081 | |
| 3082 | .. code-block:: python |
| 3083 | |
| 3084 | grouped_bar([dataset_0, dataset_1, dataset_2], |
| 3085 | tick_labels=['A', 'B'], |
| 3086 | labels=['dataset 0', 'dataset 1', 'dataset 2']) |
| 3087 | |
| 3088 | .. plot:: _embedded_plots/grouped_bar.py |
| 3089 | |
| 3090 | Parameters |
| 3091 | ---------- |
| 3092 | heights : list of array-like or dict of array-like or 2D array \ |
| 3093 | or pandas.DataFrame |
| 3094 | The heights for all x and groups. One of: |
| 3095 | |
| 3096 | - list of array-like: A list of datasets, each dataset must have |
| 3097 | the same number of elements. |
| 3098 | |
| 3099 | .. code-block:: none |
| 3100 | |
| 3101 | # category_A, category_B |
| 3102 | dataset_0 = [value_0_A, value_0_B] |
| 3103 | dataset_1 = [value_1_A, value_1_B] |
| 3104 | dataset_2 = [value_2_A, value_2_B] |
| 3105 | |
| 3106 | Example call:: |
| 3107 | |
| 3108 | grouped_bar([dataset_0, dataset_1, dataset_2]) |
| 3109 | |
| 3110 | - dict of array-like: A mapping from names to datasets. Each dataset |
| 3111 | (dict value) must have the same number of elements. |
| 3112 | |
| 3113 | Example call: |
| 3114 | |
| 3115 | .. code-block:: python |
| 3116 | |
| 3117 | data_dict = {'ds0': dataset_0, 'ds1': dataset_1, 'ds2': dataset_2} |