MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_legend_auto5

Function test_legend_auto5

lib/matplotlib/tests/test_legend.py:112–141  ·  view source on GitHub ↗

Check that the automatic placement handle a rather complex case with non rectangular patch. Related to issue #9580.

()

Source from the content-addressed store, hash-verified

110
111
112def 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')

Callers

nothing calls this directly

Calls 8

add_patchMethod · 0.80
subplotsMethod · 0.45
plotMethod · 0.45
legendMethod · 0.45
drawMethod · 0.45
transformedMethod · 0.45
get_window_extentMethod · 0.45
invertedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…