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

Function test_multiline2

lib/matplotlib/tests/test_text.py:143–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141
142@image_comparison(['multiline2'], style='mpl20')
143def test_multiline2():
144 fig, ax = plt.subplots()
145
146 ax.set_xlim(0, 1.4)
147 ax.set_ylim(0, 2)
148 ax.axhline(0.5, color='C2', linewidth=0.3)
149 sts = ['Line', '2 Lineg\n 2 Lg', '$\\sum_i x $', 'hi $\\sum_i x $\ntest',
150 'test\n $\\sum_i x $', '$\\sum_i x $\n $\\sum_i x $']
151 renderer = fig.canvas.get_renderer()
152
153 def draw_box(ax, tt):
154 r = mpatches.Rectangle((0, 0), 1, 1, clip_on=False,
155 transform=ax.transAxes)
156 r.set_bounds(
157 tt.get_window_extent(renderer)
158 .transformed(ax.transAxes.inverted())
159 .bounds)
160 ax.add_patch(r)
161
162 horal = 'left'
163 for nn, st in enumerate(sts):
164 tt = ax.text(0.2 * nn + 0.1, 0.5, st, horizontalalignment=horal,
165 verticalalignment='bottom')
166 draw_box(ax, tt)
167 ax.text(1.2, 0.5, 'Bottom align', color='C2')
168
169 ax.axhline(1.3, color='C2', linewidth=0.3)
170 for nn, st in enumerate(sts):
171 tt = ax.text(0.2 * nn + 0.1, 1.3, st, horizontalalignment=horal,
172 verticalalignment='top')
173 draw_box(ax, tt)
174 ax.text(1.2, 1.3, 'Top align', color='C2')
175
176 ax.axhline(1.8, color='C2', linewidth=0.3)
177 for nn, st in enumerate(sts):
178 tt = ax.text(0.2 * nn + 0.1, 1.8, st, horizontalalignment=horal,
179 verticalalignment='baseline')
180 draw_box(ax, tt)
181 ax.text(1.2, 1.8, 'Baseline align', color='C2')
182
183 ax.axhline(0.1, color='C2', linewidth=0.3)
184 for nn, st in enumerate(sts):
185 tt = ax.text(0.2 * nn + 0.1, 0.1, st, horizontalalignment=horal,
186 verticalalignment='bottom', rotation=20)
187 draw_box(ax, tt)
188 ax.text(1.2, 0.1, 'Bot align, rot20', color='C2')
189
190
191@image_comparison(['antialiased.png'], style='mpl20')

Callers

nothing calls this directly

Calls 7

draw_boxFunction · 0.85
axhlineMethod · 0.80
subplotsMethod · 0.45
set_xlimMethod · 0.45
set_ylimMethod · 0.45
get_rendererMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…