Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
qzhang234 opened this issue Apr 29, 2022 · 3 comments
Closed

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

qzhang234 opened this issue Apr 29, 2022 · 3 comments

Comments

@qzhang234
Copy link

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?

@qzhang234
Copy link
Author

Someone also asked the same question on Discourse:
https://discourse.matplotlib.org/t/how-to-make-mathdefault-the-default/20120?u=qzhang234

@tfpf
Copy link
Contributor

tfpf commented Apr 30, 2022

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

@anntzer
Copy link
Contributor

anntzer commented Jan 21, 2023

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
Projects
None yet
Development

No branches or pull requests

4 participants