gpt4 book ai didi

python - 在 matplotlib 图例中分隔两个字符串

转载 作者:行者123 更新时间:2023-12-04 07:50:29 24 4
gpt4 key购买 nike

这是我正在处理的代码:

import matplotlib.pyplot as plt
import numpy as np

T=[809,975,1086]

DeltaG1 = np.array([2,2.5,3])
DeltaG2=np.array([6,6.5,7])

yield_data = 500 + 500*np.random.rand(27)


legendstr=[rf'$\Delta G_1 = {x} \Delta G_2 = {y} $' for x in DeltaG1 for y in DeltaG2]


for ii in range(9):


idxs = [3*ii,3*ii+1,3*ii+2]
Sim_yield=yield_data[idxs]


plt.plot(T,Sim_yield)



plt.xlabel('X val')
plt.ylabel('Y val')
plt.legend(legendstr,bbox_to_anchor=[1,0.5],loc='right')
我想要图例字符串之间的空格,例如\DeltaG_1 =2.0 和\DeltaG_2=6 之间的空格。
我试图给像下面这样的空间,但没有奏效-
legendstr=[rf'$\Delta G_1 = {x}    \Delta G_2 = {y} $' for x in DeltaG1 for y in DeltaG2]
如何分离字符串?

最佳答案

您可以使用用反斜杠转义的空格:

legendstr = [rf'$\Delta G_1 = {x}\ \ \ \ \Delta G_2 = {y}$' for x in DeltaG1 for y in DeltaG2]
或者如约翰所说,将 latex 分成两部分:
legendstr = [rf'$\Delta G_1 = {x}$    $\Delta G_2 = {y}$' for x in DeltaG1 for y in DeltaG2]
legend with escaped spaces

关于python - 在 matplotlib 图例中分隔两个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67012114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com