Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

python - Matplotlib: Change math font size

I am making some plots with matplotlib, and I've come across a problem with the TeX rendering. It seems that the mathtext x-height is is a bit smaller than the normal Bitstream Vera Sans. See the following example:

x = linspace(0, 30, 300);
y = 0.5*rand(300)+20/(numpy.power(x-15, 2)+4);
xlabel(r'$omega$ (rad$cdot$Hz)');
ylabel(r'Intensity$^2$');
title(r'Why is $mathtext$ so much smaller than normal text?');

Plot of some random data illustrating the issue.

As you can see, it's particularly noticeable with greek letters and numbers. Ideally, I'd be able to define some scaling factor that would just make the math text a bit bigger at each font size. Is there any way to do this simply? I do not want to simply use Computer Modern everywhere. I also do not want to compile a new Tex math font, if that's even possible.

One solution that I would be on board with is using sans-serif fonts for the greek letters and numerals, but for whatever reason, matplotlib ignores formatting on those:

title('Why does $matmathsf{plot}lib$ ignore formatting for $mathsf{2}$ ($mathsf{two}), $mathbf{2}$ ($mathbf{two}) and $mathsf{omega}$?')

Title changed

I assume it's something to do with the nature of how these things are typeset, but is there any way to fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the matplotlib docs:

Additionally, you can use mathdefault{...} or its alias mathregular{...} to use the font used for regular text outside of mathtext. There are a number of limitations to this approach, most notably that far fewer symbols will be available, but it can be useful to make math expressions blend well with other text in the plot.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...