FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ticklabels font using latex · Issue #11586 · matplotlib/matplotlib · GitHub

Repository navigation

ticklabels font using latex #11586

Closed

Description

I can not change the fontstyle of the ticklabels to "sans-serif" when using latex.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)

def xticklabels_example():
    fig = plt.figure() 
    x = np.arange(20)
    y1 = np.cos(x)
    y2 = (x**2)
    y3 = (x**3)
    yn = (y1,y2,y3)
    COLORS = ('b','g','k')
    for i,y in enumerate(yn):
        ax = fig.add_subplot(len(yn),1,i+1)
        ax.plot(x, y, ls='solid', color=COLORS[i]) 
        if i != len(yn) - 1:
            # all but last 
            ax.set_xticklabels( () )
        else:
            for tick in ax.xaxis.get_major_ticks():
                tick.label.set_fontsize(14) 
                # specify integer or one of preset strings, e.g.
                #tick.label.set_fontsize('x-small') 
                tick.label.set_rotation('vertical')
    fig.suptitle('Matplotlib xticklabels Example')
    plt.show()

if __name__ == '__main__':
    xticklabels_example()

Matplotlib version

  • Operating system: python 3.6 (itom 3.1.0, www.itom.rocks)
  • Matplotlib version: 2.2.2
  • Python version: 3.6

Activity

  1. pharshalp commented on Jul 8, 2018

    Contributor

    this answer by @mdboom might help...
    https://stackoverflow.com/a/16345065

    And setting the default body text in TeX does not (by default) change the math font. This is (unfortunately standard TeX behavior).

    The solution I use when I want all sans-serif out of TeX is to use the cmbright package, which can be turned on by adding:

    rc('text.latex', preamble=r'\usepackage{cmbright}')

    Using that suggestion, here are the results...

    BEFORE

    AFTER

  2. jklymak commented on Jul 8, 2018

    Member

    That makes sense to me. OTOH, we maybe could do a better job of documenting this. I don't think its trivial for a user to know that they need to setup TeX by hand this way.

    Possibly more info at?

    https://matplotlib.org/tutorials/text/usetex.html

  3. added this to the v3.1 milestone on Jul 8, 2018
  4. added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Jul 8, 2018
  5. pharshalp commented on Jul 10, 2018

    Contributor

    I am trying to come up with a good documentation entry for this. Found 3 other issues that have the same root cause (i.e. not knowing that changing text font in TeX doesn't automatically change the math font) -- #8436, #6041, #3999.

  6. jklymak commented on Jul 10, 2018

    Member

    I think an entry that says “font selection using tex” or some such would be helpful. Show changing the basic font and the math font.

    Long term I really wonder if the Tex rendering should not consult the non-Tex font selection mechanisms at all, and users should set the preamble by hand to get what they want. That would reduce confusion in my mind.

  7. pharshalp commented on Jul 10, 2018

    Contributor
  8. ImportanceOfBeingErnest commented on Jul 21, 2018

    Member

    As commented here, one can turn the use of tex off for the ScalarFormatter such that the set font is used for the labels as well.

     ax.xaxis.get_major_formatter()._usetex = False
     ax.yaxis.get_major_formatter()._usetex = False
    

  9. pharshalp commented on Jul 21, 2018

    Contributor

    but then the tick labels won't be rendered using TeX (and other mathematical symbols, numbers will still be using TeX when text.usetex=True) which is inconsistent. When the user sets text.usetex = True the expected result is that all the fonts will be rendered using TeX. Hence, it would be better to ask the user to control the font by using text.latex.preamble.

  10. ImportanceOfBeingErnest commented on Jul 21, 2018

    Member

    The ticklabels do use tex, because text.usetex=True is set. But they are not rendered in math mode (i.e. the $ are removed). Hence they use the same font used by the rest of the document, but still through the tex system in use.

  11. pharshalp commented on Jul 21, 2018

    Contributor

    ahh right... that makes sense. But, this won't solve the issue if you have a mathematical formula in the title (or annotations) since it has to be rendered in math mode.

    usetex_maths_DejaVu-Sans.png

    usetex_maths_cmbright.png

  12. ImportanceOfBeingErnest commented on Jul 21, 2018

    Member

    In this issue, there is no math mode text used. Hence this would solve this issue.

  13. removed this from the v3.1.0 milestone on Feb 9, 2019
  14. 16 remaining items

  15. modified the milestones: v3.6.3, v3.7.0 on Jan 11, 2023
  16. modified the milestones: v3.7.0, v3.7.1 on Feb 14, 2023
  17. modified the milestones: v3.7.1, v3.7-doc on Mar 4, 2023
  18. modified the milestones: v3.7-doc, v3.8-doc on Sep 9, 2023
  19. github-actions commented on Sep 11, 2024

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  20. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Sep 12, 2024
  21. modified the milestones: v3.8-doc, v3.9-doc on Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationkeepItems to be ignored by the “Stale” Github Actiontopic: text/usetex🌱 Good first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL