python - Matplotlib Latex 分数中的垂直间距

标签 python matplotlib latex

我已经为 x 刻度标签创建了分数,但分数对我来说看起来有点局促。有没有办法增加垂直间距?

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.set_xlim(0, 10)
ax.set_xticklabels(
    ['$\\frac{{{0}}}{{{1}}}$'.format('M', x) for x in ax.get_xticks()],
    fontsize=12)

plt.show()

enter image description here

最佳答案

使用 \dfrac 可能可以解决问题。但是,我们需要修改序言。

import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rc('text.latex', preamble=r'\usepackage{amsmath}')
fig, ax = plt.subplots()

ax.set_xlim(0, 10)
ax.set_xticklabels(
    ['$\\dfrac{{{0}}}{{{1}}}$'.format('M', x) for x in ax.get_xticks()],
    fontsize=12)

enter image description here

这里有更多信息:How to write your own LaTeX preamble in Matplotlib?

关于python - Matplotlib Latex 分数中的垂直间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44915423/

相关文章:

latex - LaTex 中从左到右的树,而不是从上到下的树?

python - 与 Vampire Numbers 列表比较失败

确定当前元素是生成器的第一个元素还是最后一个元素的 Pythonic 方法?

python - matplotlib 图例 : Including markers and lines from two different graphs in one line

python - 图例中的两种线型

r - 对 RStudio 中的 'Tool(s) not installed or not in PATH: ghostcript' 警告进行故障排除

latex - 逐字命令后的空格太多

python - 新手的 Python 正则表达式列表?

python - 在 Python 中转义特殊的 HTML 字符

python - 使用matplotlib和mysql数据库创建散点图