8000 Fix vertical alignment of text (#13029) · matplotlib/matplotlib@edeccc6 · GitHub
[go: up one dir, main page]

Skip to content

Commit edeccc6

Browse files
stefraynaudtimhoffm
authored andcommitted
Fix vertical alignment of text (#13029)
* Fix vertical alignment of text This solves #13028. * Add test to make sure rotation_mode does break text position ... when rotation=0
1 parent cdc3ab1 commit edeccc6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ def test_get_rotation_mod360():
349349
assert_almost_equal(text.get_rotation(i), j)
350350

351351

352+
@pytest.mark.parametrize("ha", ["center", "right", "left"])
353+
@pytest.mark.parametrize("va", ["center", "top", "bottom",
354+
"baseline", "center_baseline"])
355+
def test_null_rotation_with_rotation_mode(ha, va):
356+
fig, ax = plt.subplots()
357+
kw = dict(rotation=0, va=va, ha=ha)
358+
t0 = ax.text(.5, .5, 'test', rotation_mode='anchor', **kw)
359+
t1 = ax.text(.5, .5, 'test', rotation_mode='default', **kw)
360+
fig.canvas.draw()
361+
assert_almost_equal(t0.get_window_extent(fig.canvas.renderer).get_points(),
362+
t1.get_window_extent(fig.canvas.renderer).get_points())
363+
364+
352365
@image_comparison(baseline_images=['text_bboxclip'])
353366
def test_bbox_clipping():
354367
plt.text(0.9, 0.2, 'Is bbox clipped?', backgroundcolor='r', clip_on=True)

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _get_layout(self, renderer):
403403
elif valign == 'baseline':
404404
offsety = ymax1 - baseline
405405
elif valign == 'center_baseline':
406-
offsety = (ymin1 + ymax1 - baseline) / 2.0
406+
offsety = ymax1 - baseline / 2.0
407407
else:
408408
offsety = ymin1
409409

0 commit comments

Comments
 (0)
0