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

Function test_align_labels

lib/matplotlib/tests/test_constrainedlayout.py:529–560  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

527
528
529def 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
563def test_suplabels():

Callers

nothing calls this directly

Calls 6

set_ylabelMethod · 0.80
align_ylabelsMethod · 0.80
subplotsMethod · 0.45
set_ylimMethod · 0.45
get_window_extentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…