Skip to content

Search for minus of any font size to get height of tex result - #17578

Merged
QuLogic merged 3 commits into
matplotlib:masterfrom
adambrown1:bugfix-issue-17574
Aug 4, 2020
Merged

QuLogic merged 3 commits into
matplotlib:masterfrom
adambrown1:bugfix-issue-17574

Conversation

@adambrown1

Copy link
Copy Markdown
Contributor

PR Summary

When searching for minus symbols in tex output, to treat them as a special case, do so for any font size not just font size 10. Minus is glyph zero of the font cmsyXX (XX being the font size).

This ensures that negative numbers have correct alignment when using tex, whatever the font size being used. This closes #17574.

The same example in the issue now gives the correct output:

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()

working_example_17574

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

When searching for minus symbols in tex output, to treat them as a 
special case, do so for any font size not just font size 10. Minus is 
glyph zero of the font cmsyXX (XX being the font size).
Comment thread lib/matplotlib/dviread.py Resolved
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc failure is unrelated, see #17595.

@QuLogic

QuLogic commented Jun 9, 2020 •

Copy link
Copy Markdown
Member

This looks good, but can you update the test (test_minus_no_descent) to also exercise this case? Probably just parametrize it over font size.

@tacaswell tacaswell added this to the v3.4.0 milestone Jun 17, 2020
@QuLogic
QuLogic merged commit 1df9efc into matplotlib:master Aug 4, 2020
@QuLogic

QuLogic commented Aug 4, 2020

Copy link
Copy Markdown
Member

Thanks @adambrown1! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants