作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 matplotlib 中有以下表达式,使用 latex 代码:
ax.set_xlabel(r'\langle \epsilon \rangle', fontsize=18)
渲染时,epsilon 明显小于括号。括号的大小可以“包裹”一个大写字母。如何让括号变小?
最佳答案
在 LaTeX 的数学模式中,可以使用以下方法使事情变得更小:
\scriptstyle
或 \scriptscriptstyle
但是这些表达式在默认的 matplotlib 后端中不起作用:
#!/usr/bin/python3
import matplotlib
custom_preamble = {
"text.usetex": True,
}
from matplotlib import pyplot as plt
x = range(5)
y = range(5)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.text(0.5, 0.5,
r"${\scriptscriptstyle(} {\scriptstyle(} (\varepsilon$",
horizontalalignment = 'center',
backgroundcolor = "white",
verticalalignment = 'center',
transform = ax.transAxes,
)
ax.plot(x, y)
fig.savefig("mwe-1.png")
结果:
然而,为了更好地支持 LaTeX,可以使用 pgf 后端,然后它就可以工作了:
import matplotlib
matplotlib.use("pgf")
# the rest is the same as in the code above
结果:
pgf
后端已添加到 matplotlib 1.3。我认为您需要在系统上安装一个可用的 XeTeX(我认为相关的二进制文件称为 xelatex
)。两个主要的 LaTeX 发行版(MiKTeX 和 TeXLive)都允许安装 XeTeX。
关于python - 如何在 matplotlib 中获得更小的 latex 括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25701916/
我是一名优秀的程序员,十分优秀!