From ba4e8db554427c508718496dae920afcdca31f0f Mon Sep 17 00:00:00 2001 From: Stephane Raynaud Date: Thu, 20 Dec 2018 12:26:37 +0100 Subject: [PATCH 1/2] Fix vertical alignment of text This solves #13028. --- lib/matplotlib/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 7cd48ef06b6a..528d0197e978 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -403,7 +403,7 @@ def _get_layout(self, renderer): elif valign == 'baseline': offsety = ymax1 - baseline elif valign == 'center_baseline': - offsety = (ymin1 + ymax1 - baseline) / 2.0 + offsety = ymax1 - baseline / 2.0 else: offsety = ymin1 From 61311663328cd819eccbf719ed65fe79518e1317 Mon Sep 17 00:00:00 2001 From: Stephane Raynaud Date: Fri, 21 Dec 2018 11:59:57 +0100 Subject: [PATCH 2/2] Add test to make sure rotation_mode does break text position ... when rotation=0 --- lib/matplotlib/tests/test_text.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 19e00be77c5b..c26edeb55abd 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -349,6 +349,19 @@ def test_get_rotation_mod360(): assert_almost_equal(text.get_rotation(i), j) +@pytest.mark.parametrize("ha", ["center", "right", "left"]) +@pytest.mark.parametrize("va", ["center", "top", "bottom", + "baseline", "center_baseline"]) +def test_null_rotation_with_rotation_mode(ha, va): + fig, ax = plt.subplots() + kw = dict(rotation=0, va=va, ha=ha) + t0 = ax.text(.5, .5, 'test', rotation_mode='anchor', **kw) + t1 = ax.text(.5, .5, 'test', rotation_mode='default', **kw) + fig.canvas.draw() + assert_almost_equal(t0.get_window_extent(fig.canvas.renderer).get_points(), + t1.get_window_extent(fig.canvas.renderer).get_points()) + + @image_comparison(baseline_images=['text_bboxclip']) def test_bbox_clipping(): plt.text(0.9, 0.2, 'Is bbox clipped?', backgroundcolor='r', clip_on=True)