Tests for a bug in which constrained layout and align_ylabels on three unevenly sized subplots, one of whose y tick labels include negative numbers, drives the non-negative subplots' y labels off the edge of the plot
()
| 527 | |
| 528 | |
| 529 | def test_align_labels(): |
| 530 | """ |
| 531 | Tests for a bug in which constrained layout and align_ylabels on |
| 532 | three unevenly sized subplots, one of whose y tick labels include |
| 533 | negative numbers, drives the non-negative subplots' y labels off |
| 534 | the edge of the plot |
| 535 | """ |
| 536 | fig, (ax3, ax1, ax2) = plt.subplots(3, 1, layout="constrained", |
| 537 | figsize=(6.4, 8), |
| 538 | gridspec_kw={"height_ratios": (1, 1, |
| 539 | 0.7)}) |
| 540 | |
| 541 | ax1.set_ylim(0, 1) |
| 542 | ax1.set_ylabel("Label") |
| 543 | |
| 544 | ax2.set_ylim(-1.5, 1.5) |
| 545 | ax2.set_ylabel("Label") |
| 546 | |
| 547 | ax3.set_ylim(0, 1) |
| 548 | ax3.set_ylabel("Label") |
| 549 | |
| 550 | fig.align_ylabels(axs=(ax3, ax1, ax2)) |
| 551 | |
| 552 | fig.draw_without_rendering() |
| 553 | after_align = [ax1.yaxis.label.get_window_extent(), |
| 554 | ax2.yaxis.label.get_window_extent(), |
| 555 | ax3.yaxis.label.get_window_extent()] |
| 556 | # ensure labels are approximately aligned |
| 557 | np.testing.assert_allclose([after_align[0].x0, after_align[2].x0], |
| 558 | after_align[1].x0, rtol=0, atol=1e-05) |
| 559 | # ensure labels do not go off the edge |
| 560 | assert after_align[0].x0 >= 1 |
| 561 | |
| 562 | |
| 563 | def test_suplabels(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…