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

Function test_align_labels

lib/matplotlib/tests/test_figure.py:31–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29@image_comparison(['figure_align_labels'], extensions=['png', 'svg'], style='mpl20',
30 tol=0 if platform.machine() == 'x86_64' else 0.01)
31def test_align_labels():
32 fig = plt.figure(layout='tight')
33 gs = gridspec.GridSpec(3, 3)
34
35 ax = fig.add_subplot(gs[0, :2])
36 ax.plot(np.arange(0, 1e6, 1000))
37 ax.set_ylabel('Ylabel0 0')
38 ax = fig.add_subplot(gs[0, -1])
39 ax.plot(np.arange(0, 1e4, 100))
40
41 for i in range(3):
42 ax = fig.add_subplot(gs[1, i])
43 ax.set_ylabel('YLabel1 %d' % i)
44 ax.set_xlabel('XLabel1 %d' % i)
45 if i in [0, 2]:
46 ax.xaxis.set_label_position("top")
47 ax.xaxis.tick_top()
48 if i == 0:
49 for tick in ax.get_xticklabels():
50 tick.set_rotation(90)
51 if i == 2:
52 ax.yaxis.set_label_position("right")
53 ax.yaxis.tick_right()
54
55 for i in range(3):
56 ax = fig.add_subplot(gs[2, i])
57 ax.set_xlabel(f'XLabel2 {i}')
58 ax.set_ylabel(f'YLabel2 {i}')
59
60 if i == 2:
61 ax.plot(np.arange(0, 1e4, 10))
62 ax.yaxis.set_label_position("right")
63 ax.yaxis.tick_right()
64 for tick in ax.get_xticklabels():
65 tick.set_rotation(90)
66
67 fig.align_labels()
68
69
70@image_comparison(['figure_align_titles_tight.png',

Callers

nothing calls this directly

Calls 10

figureMethod · 0.80
add_subplotMethod · 0.80
set_ylabelMethod · 0.80
set_xlabelMethod · 0.80
tick_topMethod · 0.80
set_rotationMethod · 0.80
tick_rightMethod · 0.80
align_labelsMethod · 0.80
plotMethod · 0.45
set_label_positionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…