suptitle中matplotlib上标的字体紧排(字符之间的水平间距)?

2024-05-12 14:45:21 发布

您现在位置:Python中文网/ 问答频道 /正文

请考虑以下代码段:

#!/usr/bin/env python3

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
mynumber = 0
fig.suptitle(r'Yeah, this: $\mathregular{{2^{{ {}+1 }} }}$'.format(mynumber), fontsize=14)
plt.show()

在Windows 10下的MINGW64(MSYS2)下的Matplotlib 3.1.1和Python 3.7.5上,我得到以下绘图标题:

fig_suptitle

但是,根据我的口味,0+(以及+1之间)文本中的水平空格/紧排有点过多;我想要一个更紧的紧排,类似这样的(用Gimp编辑的照片):

fig_suptitle_02

这是否可以在Matplotlib中执行/控制,如果可以,我如何控制它(打印标题文本中上标的紧排,使用默认字体)?你知道吗


Tags: 文本importenv标题binmatplotlibusr代码段
1条回答
网友
1楼 · 发布于 2024-05-12 14:45:21

再次感谢@ImportanceOfBeingErnest->;\!实际上是一个TeX命令,它意味着:

https://tex.stackexchange.com/questions/455375/what-does-aka-backslash-exclamation-mark-do

The command \! is only allowed in math mode ... It's purpose is to insert a negative thin space, which is useful in several places ... The negative spacing of \! exactly matches the positive one by \,

。。。所以,结果证明,它可以“叠加”,也就是说,重复,为了更紧;我只需要重复两次,就可以得到几乎和我在OP上买的一样的输出:

fig.suptitle(r'Yeah, this: $\mathregular{{2^{{ {}\!\!+\!\!1 }} }}$'.format(mynumber), fontsize=14)

所以,这很好,现在。。。你知道吗

相关问题 更多 >