diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index 74f1d911b561..4184d6421c84 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -24,7 +24,7 @@ except ImportError: import dummy_threading as threading from contextlib import nullcontext -from math import radians, cos, sin +from math import radians, cos, sin, sqrt import numpy as np from PIL import Image @@ -208,10 +208,13 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): xo, yo = font.get_bitmap_offset() xo /= 64.0 yo /= 64.0 + h = sqrt(xo**2 + yo**2) xd = d * sin(radians(angle)) yd = d * cos(radians(angle)) + xo = h * cos(radians(angle)) + yo = h * sin(radians(angle)) x = round(x + xo + xd) - y = round(y + yo + yd) + y = round(y + yo - yd) self._renderer.draw_text_image(font, x, y + 1, angle, gc) def get_text_width_height_descent(self, s, prop, ismath):