matplotlib tex label添加/删除空白

2024-10-04 05:27:27 发布

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

我有一个图,其中y标签上有一个数量级的上标,我用下面的一行:

# plt is acquired from matplotlib.pyplot
# orderMagnitude is a variable taken from a different part of the code
plt.ylabel('${\mathrm{Intensity (10^'+str(int(orderMagnitude))+')}}$')

添加{\mathrm{..}}部分是因为没有它,整个文本将是斜体(除了实际数字)。我现在看到的这条线似乎去掉了y(强度)和开头“(”之间的空白,但似乎在orderMagnitude之后添加了一些空白(见图)。在

enter image description here

有人知道为什么会这样吗?在


Tags: frommatplotlibisplt标签variable空白taken
1条回答
网友
1楼 · 发布于 2024-10-04 05:27:27

你不需要把整条线都置于数学模式,那是你遇到麻烦的一部分。尤其是,您将整个等式放在\mathrm{}中,而不是仅仅{Intensity }。下面的内容可能会更好,您不应该在结尾处获得额外的空白:

plt.ylabel('Intensity $(10^{' + str(int(orderMagnitude)) + '})$')

相关问题 更多 >