matplotlib mathtext \ frac太小了

问题描述 投票:6回答:2

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

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

我指定的字体大小为18,A和B的渲染速度为12.6 pt,而C的渲染速度为18 pt。我希望A,B和C都是相同的大小。我该怎么做呢?

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

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

你得到一个分数,其中A,B和C都是相同的大小,但如果你这样做

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

与文本内联,你得到的A和B渲染为12.6 pt,而C则渲染为18 pt。因此看来matplotlib的mathtext正在模仿LaTeX的内联模式。在LaTeX中你可以写

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

然后A,B和C都是相同的大小,即使在内联模式下也是如此。我在matplotlib中尝试了这个,但mathtext没有识别命令\ displaystyle。 =(

有没有办法让这个在Matplotlib的mathtext中工作,或者我在我的.matplotlibrc文件中将text.usetex更改为true? (如果可能的话,我想继续使用mathtext,因为它要快得多。)

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

python matplotlib latex
2个回答
1
投票

对于任何绊倒这个并且也不想将"text.usetex"设置为True,matplotlib now supports \dfrac宏(相当于LaTeX中的\displaystyle\frac)以取代\frac自2.1版以来


2
投票

如你所说,你可以使用\ displaystyle修复它:

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

为了允许matplotlib使用latex进行所有文本处理,你必须在matplotlibrc中将text.usetex变量定义为True:

text.usetex          : True

我做了一个例子来验证它并且运行良好:

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

对不起,但由于我是新人,我无法发布任何图片。

© www.soinside.com 2019 - 2024. All rights reserved.