()
| 6195 | @image_comparison(['twin_spines.png'], remove_text=True, style='_classic_test', |
| 6196 | tol=0 if platform.machine() == 'x86_64' else 0.022) |
| 6197 | def test_twin_spines(): |
| 6198 | |
| 6199 | def make_patch_spines_invisible(ax): |
| 6200 | ax.set_frame_on(True) |
| 6201 | ax.patch.set_visible(False) |
| 6202 | ax.spines[:].set_visible(False) |
| 6203 | |
| 6204 | fig = plt.figure(figsize=(4, 3)) |
| 6205 | fig.subplots_adjust(right=0.75) |
| 6206 | |
| 6207 | host = fig.add_subplot() |
| 6208 | par1 = host.twinx() |
| 6209 | par2 = host.twinx() |
| 6210 | |
| 6211 | # Offset the right spine of par2. The ticks and label have already been |
| 6212 | # placed on the right by twinx above. |
| 6213 | par2.spines.right.set_position(("axes", 1.2)) |
| 6214 | # Having been created by twinx, par2 has its frame off, so the line of |
| 6215 | # its detached spine is invisible. First, activate the frame but make |
| 6216 | # the patch and spines invisible. |
| 6217 | make_patch_spines_invisible(par2) |
| 6218 | # Second, show the right spine. |
| 6219 | par2.spines.right.set_visible(True) |
| 6220 | |
| 6221 | p1, = host.plot([0, 1, 2], [0, 1, 2], "b-") |
| 6222 | p2, = par1.plot([0, 1, 2], [0, 3, 2], "r-") |
| 6223 | p3, = par2.plot([0, 1, 2], [50, 30, 15], "g-") |
| 6224 | |
| 6225 | host.set_xlim(0, 2) |
| 6226 | host.set_ylim(0, 2) |
| 6227 | par1.set_ylim(0, 4) |
| 6228 | par2.set_ylim(1, 65) |
| 6229 | |
| 6230 | host.yaxis.label.set_color(p1.get_color()) |
| 6231 | par1.yaxis.label.set_color(p2.get_color()) |
| 6232 | par2.yaxis.label.set_color(p3.get_color()) |
| 6233 | |
| 6234 | tkw = dict(size=4, width=1.5) |
| 6235 | host.tick_params(axis='y', colors=p1.get_color(), **tkw) |
| 6236 | par1.tick_params(axis='y', colors=p2.get_color(), **tkw) |
| 6237 | par2.tick_params(axis='y', colors=p3.get_color(), **tkw) |
| 6238 | host.tick_params(axis='x', **tkw) |
| 6239 | |
| 6240 | |
| 6241 | @image_comparison(['twin_spines_on_top.png', 'twin_spines_on_top.png'], |
nothing calls this directly
no test coverage detected
searching dependent graphs…