Matplotlib:更改数学字体大小 [英] Matplotlib: Change math font size

查看:136
本文介绍了Matplotlib:更改数学字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matplotlib进行一些绘图,但是遇到了TeX渲染问题.似乎mathtext的x高度比正常的Bitstream Vera Sans小一些.请参见以下示例:

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?');

如您所见,希腊字母和数字特别引人注目.理想情况下,我将能够定义一些缩放因子,以使每种字体大小的数学文本都更大.有什么办法可以简单地做到这一点吗?我不是要在任何地方简单地使用Computer Modern.如果可能的话,我也不想编译新的Tex数学字体.

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.

我会采用的一种解决方案是对希腊字母和数字使用sans-serif字体,但是由于某种原因,matplotlib忽略了这些字体的格式:

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 $mat\mathsf{plot}lib$ ignore formatting for $\mathsf{2}$ ($\mathsf{two}), $\mathbf{2}$ ($\mathbf{two}) and $\mathsf{\omega}$?')

我认为这与这些内容的排版方式有关,但是有什么办法可以解决?

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

推荐答案

来自 matplotlib文档:

此外,您可以使用\mathdefault{...}或其别名 \mathregular{...}以使用用于常规文本的字体 数学文字.这种方法有很多局限性,大多数 值得注意的是,可用的符号要少得多,但这很有用 使数学表达式与绘图中的其他文本很好地融合.

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.

这篇关于Matplotlib:更改数学字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆