Skip to content

[ENH]: Global setting to make /mathdefault the default math type  #22937

Closed

Description

@qzhang234

Problem

I am trying to generate scientific journal compatible figures in Matplotlib. Most of the journals have specific font requirements (e.g. Times New Roman) and I find myself typing something like $\mathdefault{_x}$ instead of just ${_x}$ throughout the script, which reduces the readability of the scrpit.

Proposed solution

Is it possible to have a global setting like matplotlib.rcParams that can be set once for the entire figure?

Activity

  1. qzhang234 commented on Apr 29, 2022

    @qzhang234
    Author
  2. tfpf commented on Apr 30, 2022

    @tfpf
    Contributor

    It is possible to set a single font for the entire figure, but multiple rcParams have to be set (as far as I know—if that's not the case, hopefully somebody will correct me). As a temporary workaround to avoid having to type mathdefault over and over again, if it is specifically Times New Roman that is needed, consider using STIX, which is designed to blend with Times New Roman.

    import matplotlib.pyplot as plt
    plt.rc('mathtext', fontset='stix')
    plt.rc('font', family='STIXGeneral')
    plt.text(.1, .5, 'Normal Text\n$y=e^x$\n$\mathbf{A}x=b$', size=20)
    plt.show()
    

    same_font_in_mpl

    Any other font can be used as well.

    import matplotlib.pyplot as plt
    plt.rc('mathtext', fontset='custom', it='Segoe Script:italic', bf='Segoe Script:bold', rm='Segoe Script')
    plt.rc('font', family='Segoe Script')
    plt.text(.1, .5, 'Normal Text\n$y=e^x$\n$\mathbf{A}x=b$', size=20)
    plt.show()
    

    (It may be necessary to delete the font cache if you are using a recently-installed font.)

  3. anntzer commented on Jan 21, 2023

    @anntzer
    Contributor

    I believe that the solution linked on discourse (setting mathtext.fontset = "custom", mathtext.rm = ..., mathtext.sf = ... as desired) is effectively the correct one, and using STIX as suggested by @tfpf should work too. Closing, but feel free to ping for reopen if you think more should be done.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions