我已经为我的 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()
请您参考如下方法:
使用 \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)
此处提供更多信息:How to write your own LaTeX preamble in Matplotlib?
