如何在matplotlib标题中包含符号

时间:2020-08-21 00:33:37

标签: python matplotlib

我想在matplotlib标题中包含符号,但是以下代码不起作用。

import matplotlib.pyplot as plt
import numpy as np

N_combs=10
t1 = np.random.randint(100, size=(N_combs,2))
g1=np.random.randint(100, size=(N_combs,2))
plt.plot(range(100), np.random.randn(100, N_combs))    
plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])

错误:

  File "<ipython-input-972-589f95b4b1cf>", line 8, in <module>
    plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])

  File "<ipython-input-972-589f95b4b1cf>", line 8, in <listcomp>
    plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])

TypeError: cannot unpack non-iterable numpy.int32 object

相反,如果我使用plt.legend,它将起作用。

1 个答案:

答案 0 :(得分:1)

使用格式设置功能将每个Latex字符串组合在一起。

client_max_body_size

enter image description here