Description
For font features/languages, I ran into an issue in that the Text
object is only supplied to Renderer.draw_text
if the string is not multiline:
matplotlib/lib/matplotlib/text.py
Line 805 in b4cb934
I tried a small change:
diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py
index 3b0de58814..b255a93c52 100644
--- a/lib/matplotlib/text.py
+++ b/lib/matplotlib/text.py
@@ -800,9 +800,7 @@ class Text(Artist):
angle = self.get_rotation()
for line, wh, x, y in info:
-
- mtext = self if len(info) == 1 else None
x = x + posx
y = y + posy
if renderer.flipy():
@@ -816,14 +814,19 @@ class Text(Artist):
else:
textrenderer = renderer
- if self.get_usetex():
- textrenderer.draw_tex(gc, x, y, clean_line,
- self._fontproperties, angle,
- mtext=mtext)
- else:
- textrenderer.draw_text(gc, x, y, clean_line,
- self._fontproperties, angle,
- ismath=ismath, mtext=mtext)
+ xt, yt = self.get_transform().inverted().transform((x, y))
+ with cbook._setattr_cm(self, _x=xt, _y=yt, _text=clean_line,
+ convert_xunits=lambda x: x,
+ convert_yunits=lambda y: y,
+ _horizontalalignment='left', _verticalalignment='bottom'):
+ if self.get_usetex():
+ textrenderer.draw_tex(gc, x, y, clean_line,
+ self._fontproperties, angle,
+ mtext=self)
+ else:
+ textrenderer.draw_text(gc, x, y, clean_line,
+ self._fontproperties, angle,
+ ismath=ismath, mtext=self)
gc.restore()
renderer.close_group('text')
AFAICT, only the PGF backend uses mtext
and under certain conditions will place the text using the original position and alignment instead of the x
/y
passed to draw_text
. Unfortunately, these don't seem to match (I assume the x/y passed in accounts for the descenders and other flourishes), so this breaks the PGF tests. I wonder if there's a better condition to be put in here:
matplotlib/lib/matplotlib/backends/backend_pgf.py
Lines 697 to 700 in 6db18d5
Originally posted by @QuLogic in #29695 (comment)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status