Skip to content

Vertical alignment of tick labels containing minus in font size other than 10 with usetex=True #17574

Closed

Description

@adambrown1

Bug report

Bug summary

When TeX is used to typset text, minus signs cause a vertical offset in tick labels for certain font sizes. This is related to #6323, which was fixed but only for given font sizes.

The problem with the fix in #16366 seems to be that it looks for character 0 in font "cmsy10". I am not an expert, but I think the 10 refers to the font size, and for example "cmsy8" is used for 8 pt font.

Code for reproduction

from matplotlib import pyplot as plt
fig = plt.figure(dpi=300)
plt.rc('text', usetex=True)
ax = fig.add_subplot(1,2,1)
plt.plot((-7.,0.,7.), (-1.,0.,1.), 'r-')
plt.rc('text', usetex=True)
ax = fig.add_subplot(1,2,2)
plt.plot((-7.,0.,7.), (-1.,0.,1.), 'r-')
plt.xticks(fontsize=8)
plt.yticks(fontsize=8)
plt.show()

Outcome

bad_minus_size_8

On the left (font size 10) axis labels are correctly aligned are whereas on the right (font size 8) those labels which contain a minus sign are noticably lower.

Matplotlib version

  • Operating system: mac OS 10.15.4
  • Matplotlib version: 3.2.1 (installed using pip, with Special-case usetex minus to zero depth. #16366 manually applied)
  • Matplotlib backend module://ipykernel.pylab.backend_inline:
  • Python version: 3.7.1
  • Jupyter version (if applicable): 4.4.0

Activity

  1. anntzer commented on Jun 4, 2020

    @anntzer
    Contributor

    Changing the check to match any cmsy\d+ seems reasonable, do you want to make a PR?

  2. jkseppan commented on Aug 4, 2020

    @jkseppan
    Member

    Another solution could be to add \vphantom{-} to the beginning of all tick labels when usetex is enabled.

  3. added this to the v3.4.0 milestone on Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions