Check that the automatic placement handle a rather complex case with non rectangular patch. Related to issue #9580.
()
| 110 | |
| 111 | |
| 112 | def test_legend_auto5(): |
| 113 | """ |
| 114 | Check that the automatic placement handle a rather complex |
| 115 | case with non rectangular patch. Related to issue #9580. |
| 116 | """ |
| 117 | fig, axs = plt.subplots(ncols=2, figsize=(9.6, 4.8)) |
| 118 | |
| 119 | leg_bboxes = [] |
| 120 | for ax, loc in zip(axs.flat, ("center", "best")): |
| 121 | # An Ellipse patch at the top, a U-shaped Polygon patch at the |
| 122 | # bottom and a ring-like Wedge patch: the correct placement of |
| 123 | # the legend should be in the center. |
| 124 | for _patch in [ |
| 125 | mpatches.Ellipse( |
| 126 | xy=(0.5, 0.9), width=0.8, height=0.2, fc="C1"), |
| 127 | mpatches.Polygon(np.array([ |
| 128 | [0, 1], [0, 0], [1, 0], [1, 1], [0.9, 1.0], [0.9, 0.1], |
| 129 | [0.1, 0.1], [0.1, 1.0], [0.1, 1.0]]), fc="C1"), |
| 130 | mpatches.Wedge((0.5, 0.5), 0.5, 0, 360, width=0.05, fc="C0") |
| 131 | ]: |
| 132 | ax.add_patch(_patch) |
| 133 | |
| 134 | ax.plot([0.1, 0.9], [0.9, 0.9], label="A segment") # sthg to label |
| 135 | |
| 136 | leg = ax.legend(loc=loc) |
| 137 | fig.canvas.draw() |
| 138 | leg_bboxes.append( |
| 139 | leg.get_window_extent().transformed(ax.transAxes.inverted())) |
| 140 | |
| 141 | assert_allclose(leg_bboxes[1].bounds, leg_bboxes[0].bounds) |
| 142 | |
| 143 | |
| 144 | @image_comparison(['legend_various_labels.png'], remove_text=True, style='mpl20') |
nothing calls this directly
no test coverage detected
searching dependent graphs…