In Matplotlib 2, using rcParams, I can set mathtext.fontset="cm"
or mathtext.fontset="dejavusans"
to control the font used in math-mode text in my figure. Is there a way so that within a single figure, I draw one text with one fontset, then a different text with a different fontset?
Asked
Active
Viewed 171 times
0

marius
- 1,352
- 1
- 13
- 29
-
1Font sets are global. I think `mathtext` is not very flexible. I'm not sure but you might want to try rendering your text with LaTeX. Then you might be able to use `font.set_family()` like in [this example](https://matplotlib.org/examples/pylab_examples/fonts_demo.html). – Y. Luo Jun 27 '17 at 03:37
-
Thanks, that basically works, I made the figure globally with "dejavusans", then did `usetex` for the pieces I wanted in "cm". Feel free to submit an answer if you want, I'm happy to mark it answered. – marius Jun 27 '17 at 17:17
-
You're welcome. That's very nice of you. But I don't have a real good answer other than the "compromised" solution. I'll try not to waste other's time. – Y. Luo Jun 27 '17 at 18:08
-
A slightly different workaround: `mathtext` has half a dozen defined sub-text-types, meant for italic and bold-italic, etc. You can set each of them to a different font as well as style. If your use of fonts is systematic, this might be a readable solution; if it's a one-off, doing it explicitly with `usetex` makes sense to me. The `mathtext` way is a small edit to an answer to this question: https://stackoverflow.com/questions/44779531/make-a-label-both-italic-and-bold-style-in-matplotlib-with-stix-font – cphlewis Jun 28 '17 at 17:28