Create a hat graph. Parameters ---------- ax : matplotlib.axes.Axes The Axes to plot into. xlabels : list of str The category names to be displayed on the x-axis. values : (M, N) array-like The data values. Rows are the groups (len(group_labe
(ax, xlabels, values, group_labels)
| 12 | |
| 13 | |
| 14 | def hat_graph(ax, xlabels, values, group_labels): |
| 15 | """ |
| 16 | Create a hat graph. |
| 17 | |
| 18 | Parameters |
| 19 | ---------- |
| 20 | ax : matplotlib.axes.Axes |
| 21 | The Axes to plot into. |
| 22 | xlabels : list of str |
| 23 | The category names to be displayed on the x-axis. |
| 24 | values : (M, N) array-like |
| 25 | The data values. |
| 26 | Rows are the groups (len(group_labels) == M). |
| 27 | Columns are the categories (len(xlabels) == N). |
| 28 | group_labels : list of str |
| 29 | The group labels displayed in the legend. |
| 30 | """ |
| 31 | |
| 32 | values = np.asarray(values) |
| 33 | color_cycle_colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] |
| 34 | |
| 35 | # Draw the hats |
| 36 | bars = ax.grouped_bar( |
| 37 | (values - values[0]).T, bottom=values[0], tick_labels=xlabels, |
| 38 | labels=group_labels, edgecolor='black', group_spacing=0.8, |
| 39 | colors=['none'] + color_cycle_colors) |
| 40 | |
| 41 | # Attach a text label on top of each bar |
| 42 | for bc, heights in zip(bars.bar_containers, values): |
| 43 | ax.bar_label(bc, heights, padding=4) |
| 44 | |
| 45 | |
| 46 | # Initialise labels and a numpy array make sure you have |
no test coverage detected
searching dependent graphs…