| 14 | @image_comparison(['bbox_inches_tight'], remove_text=True, style='mpl20', |
| 15 | savefig_kwarg={'bbox_inches': 'tight'}) |
| 16 | def test_bbox_inches_tight(text_placeholders): |
| 17 | #: Test that a figure saved using bbox_inches='tight' is clipped correctly |
| 18 | data = [[66386, 174296, 75131, 577908, 32015], |
| 19 | [58230, 381139, 78045, 99308, 160454], |
| 20 | [89135, 80552, 152558, 497981, 603535], |
| 21 | [78415, 81858, 150656, 193263, 69638], |
| 22 | [139361, 331509, 343164, 781380, 52269]] |
| 23 | |
| 24 | col_labels = ('Freeze', 'Wind', 'Flood', 'Quake', 'Hail') |
| 25 | row_labels = [f'{x} year' for x in (100, 50, 20, 10, 5)] |
| 26 | |
| 27 | rows = len(data) |
| 28 | ind = np.arange(len(col_labels)) + 0.3 # the x locations for the groups |
| 29 | cell_text = [] |
| 30 | width = 0.4 # the width of the bars |
| 31 | yoff = np.zeros(len(col_labels)) |
| 32 | # the bottom values for stacked bar chart |
| 33 | fig, ax = plt.subplots(1, 1) |
| 34 | for row in range(rows): |
| 35 | ax.bar(ind, data[row], width, bottom=yoff, align='edge') |
| 36 | yoff = yoff + data[row] |
| 37 | cell_text.append([f'{x / 1000:1.1f}' for x in yoff]) |
| 38 | plt.xticks([]) |
| 39 | plt.xlim(0, 5) |
| 40 | plt.legend(['1', '2', '3', '4', '5'], loc=(1.2, 0.2)) |
| 41 | fig.legend(['a', 'b', 'c', 'd', 'e'], bbox_to_anchor=(0, 0.2), loc='lower left') |
| 42 | # Add a table at the bottom of the axes |
| 43 | cell_text.reverse() |
| 44 | plt.table(cellText=cell_text, rowLabels=row_labels, colLabels=col_labels, |
| 45 | loc='bottom') |
| 46 | |
| 47 | |
| 48 | @image_comparison(['bbox_inches_tight_suptile_legend'], |