matplotlib mathtext \frac太小了

时间:2021-08-23 23:39:35

When I give matplotlib a annotation string such as

当我给matplotlib一个注释字符串,比如

'$\frac{A}{B} = C$'

and I specify a fontsize of 18, the A and B are rendered at 12.6 pt, while the C is rendered at 18 pt. I want A, B, and C to all be the same size. How do I do this?

我指定了一个18的字体大小,a和B在12.6 pt上呈现,C在18pt上呈现。我该怎么做呢?

In a LaTeX document, if you give the commands

在LaTeX文档中,如果您提供命令

\begin{equation}
\frac{A}{B} = C
\end{equation}

you get a fraction, where A, B, and C are all the same size, but if you do

你得到一个分数,a B C都是一样的大小,但是如果你这样做的话

$\frac{A}{B} = C$

inline with text, you get the A and B rendered at 12.6 pt, while the C is rendered at 18 pt. Thus it appears matplotlib's mathtext is emulating LaTeX's inline mode. In LaTeX you can write

内联文本时,A和B在12.6 pt上呈现,C在18pt上呈现。因此,matplotlib的mathtext正在模拟LaTeX的内联模式。在LaTeX中可以写东西

$\displaystyle\frac{A}{B} = C$

and then A, B, and C are all the same size, even in inline mode. I tried this in matplotlib, but mathtext did not recognize the command \displaystyle. =(

然后A, B, C都是相同的大小,甚至在内联模式下。我在matplotlib中尝试过,但是mathtext不认识命令\displaystyle。=(

Is there a way to get this to work in Matplotlib's mathtext, or am I stuck changing text.usetex to true in my .matplotlibrc file? (If possible I would like to stay with mathtext since it is a lot faster.)

在Matplotlib的mathtext中,是否有一种方法可以让它工作,或者我不得不修改文本。在我的。matplotlibrc文件中使用usetex。(如果可能的话,我想继续使用mathtext,因为它要快得多。)

My setup: matplotlib v1.2.0 python 2.7 OS X 10.8

我的设置:matplotlib v1.2.0 python 2.7 OS X 10.8。

1 个解决方案

#1


1  

As you said, you can fix it by using \displaystyle:

正如您所说,您可以使用\displaystyle来修复它:

$\displaystyle\frac{A}{B} = C$

In order to allow matplotlib to use latex for all text handling you have to define in your matplotlibrc the text.usetex variable as True:

为了允许matplotlib使用latex来处理所有文本,您必须在matplotlibrc中定义文本。usetex变量是真实的:

text.usetex          : True

I made a little example to verify it and it is working well:

我举了一个例子来验证它,它运行得很好:

import matplotlib.pyplot as plt
plt.plot(range(200))
plt.text(100,50,r'$\displaystyle\frac{A}{B}=C$')

I am sorry but since I am new, I can not post any image.

很抱歉,因为我是新的,所以我不能张贴任何图片。

#1


1  

As you said, you can fix it by using \displaystyle:

正如您所说,您可以使用\displaystyle来修复它:

$\displaystyle\frac{A}{B} = C$

In order to allow matplotlib to use latex for all text handling you have to define in your matplotlibrc the text.usetex variable as True:

为了允许matplotlib使用latex来处理所有文本,您必须在matplotlibrc中定义文本。usetex变量是真实的:

text.usetex          : True

I made a little example to verify it and it is working well:

我举了一个例子来验证它,它运行得很好:

import matplotlib.pyplot as plt
plt.plot(range(200))
plt.text(100,50,r'$\displaystyle\frac{A}{B}=C$')

I am sorry but since I am new, I can not post any image.

很抱歉,因为我是新的,所以我不能张贴任何图片。