我创建了一个情节,我希望我绘制的第一个项目的标签部分是字符串,部分是数组“t”的元素0。我尝试将变量the_initial_state设置为等于字符串:
the_initial_state = str('the initial state')
情节如下:
plt.figure(5)
fig = plt.figure(figsize=(6,6), dpi=1000)
plt.rc("font", size=10)
plt.title("Time-Dependent Probability Density Function")
plt.xlabel("x")
plt.xlim(-10,10)
plt.ylim(0,0.8)
plt.plot(x,U,'k--')
**plt.plot(x,Pd[0],'r',label= the_initial_state, label =t[0])**
plt.plot(x,Pd[1],'m',label=t[1])
plt.plot(x,Pd[50],'g',label=t[50])
plt.plot(x,Pd[100],'c',label=t[100])
plt.legend(title = "time", bbox_to_anchor=(1.05, 0.9), loc=2, borderaxespad=0.)
但是我收到** **指示的行的“无效语法”错误。
有没有办法让一个包含字符串和数组元素的标签到一个固定的小数位?
答案 0 :(得分:1)