Skip to content

Commit 19355c6

Browse files
committed
ps: Fix anchoring of rotated usetex text
In PostScript, usetex text is anchored to the bottom left for replacement by psfrag, while in Matplotlib, text is placed by the baseline usually. So PostScript subtracts the text depth from the y position, but for rotated text, this subtraction should also be in a rotated direction.
1 parent e9e3579 commit 19355c6

File tree

6 files changed

+10843
-2
lines changed

6 files changed

+10843
-2
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,10 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
588588
s = fontcmd % s
589589
tex = r'\color[rgb]{%s} %s' % (color, s)
590590

591-
# Stick to the bottom alignment.
592-
pos = _nums_to_str(x, y-bl)
591+
# Stick to bottom-left alignment, so subtract descent from the text-normal
592+
# direction since text is normally positioned by its baseline.
593+
rangle = np.radians(angle + 90)
594+
pos = _nums_to_str(x - bl * np.cos(rangle), y - bl * np.sin(rangle))
593595
self.psfrag.append(
594596
r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}' % (
595597
thetext, angle, fontsize, fontsize*1.25, tex))

0 commit comments

Comments
 (0)