简体   繁体   English

如何在matplotlib中获得较小的乳胶支架?

[英]How to get smaller latex brackets in matplotlib?

I have the following expression in matplotlib, using latex code: 我在matplotlib中使用乳胶代码具有以下表达式:

ax.set_xlabel(r'\langle \epsilon \rangle', fontsize=18)

While rendering the epsilon is significantly smaller than the brackets. 在渲染时,ε明显小于括号。 The brackets are sized to "wrap" an uppercase letter. 括号的大小可“包装”大写字母。 How do I make the brackets smaller? 如何缩小支架?

In LaTeX's math-mode one can make things smaller using: 在LaTeX的数学模式下,可以使用以下方法缩小体积:

  • \\scriptstyle or \\scriptstyle
  • \\scriptscriptstyle

However these expressions don't work in default matplotlib backend: 但是这些表达式在默认的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")

Results in: 结果是:

在此处输入图片说明

However for a better LaTeX support one can use pgf backend, and then it works: 但是,为了获得更好的LaTeX支持,可以使用pgf后端,然后可以使用:

import matplotlib
matplotlib.use("pgf")
# the rest is the same as in the code above

Result: 结果:

在此处输入图片说明

pgf backend was added to matplotlib 1.3. pgf后端已添加到matplotlib 1.3。 I think You'll need a working XeTeX installed on Your system (I think the relative binary is called xelatex ). 我认为您需要在系统上安装可运行的XeTeX(我认为相对二进制文件称为xelatex )。 Both major LaTeX distributions (MiKTeX and TeXLive) allow to install XeTeX. 两种主要的LaTeX发行版(MiKTeX和TeXLive)都允许安装XeTeX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM