用精确值标记图中的曲线

用精确值标记图中的曲线

在以下代码中,我们在一个图if Ju<11:中绘制了10条曲线 如何在读者发现每一条线是Ju的每条曲线上书写。 例如,在每一行上我们可以看到Ju =1,另一行Ju=2和...

我指的是在每行上标注其确切使用值

fig,(ax1) = plt.subplots(1)
for n in np.arange(100,200,100):
    for z in np.arange(3,4):
        ET_list=[]
        uf_list=[]
        for xx in range(1,819):
            for uf in np.linspace(1e-26,1e-20,10):
                Ju = dfimppara.iloc[xx,1]
                Jl = dfimppara.iloc[xx,2]
                lim = Ju - Jl
                if lim > 1:
                    pass
                else:
                    if Ju<11:
                        ET_list.append(ET(xx,z,n,1,uf)/ET(xx,0))
                        uf_list.append(uf)  
                        ax1.plot(uf_list,ET_list)  
                    else:
                        pass

ax1.title.set_text('Fig1')
plt.xlabel('Un')
plt.ylabel('TT')
#plt.xscale('log')
plt.show()

请帮忙

zzxcyj 回答:用精确值标记图中的曲线

您可以使用text(x,y,s)中的matplotlib函数。这里是文档: https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.text.html

text包含3个主要参数xy,它们是文本的坐标。 s是您要在绘图上写入的字符串。对于您来说,它将类似于"Ju={:d}".format(Ju)

您应该有类似的东西

fig,(ax1) = plt.subplots(1)
for n in np.arange(100,200,100):
    for z in np.arange(3,4):
        ET_list=[]
        uf_list=[]
        for xx in range(1,819):
            for uf in np.linspace(1e-26,1e-20,10):
                Ju = dfimppara.iloc[xx,1]
                Jl = dfimppara.iloc[xx,2]
                lim = Ju - Jl
                if lim > 1:
                    pass
                else:
                    if Ju<11:
                        ET_list.append(ET(xx,z,n,1,uf)/ET(xx,0))
                        uf_list.append(uf)  
                        ax1.plot(uf_list,ET_list)
                        x = # Put here a float or int that represent the x coordinates of the text
                        y = # Put here a float or int that represent the y coordinates of the text
                        s = "Ju={:d}".format(Ju)
                        ax1.text(x,s)
                    else:
                        pass
ax1.title.set_text('Fig1')
plt.xlabel('Un')
plt.ylabel('TT')
plt.show()

您可以尝试的其他方法只是将其作为图例。您可以使用label中的ax.plot()参数为每行设置标签来设置图例。 像这样:

fig,ET_list,label="Ju={:d}".format(Ju))
                    else:
                        pass
ax1.title.set_text('Fig1')
# You have to set the legend
ax1.legend(loc="best")
plt.xlabel('Un')
plt.ylabel('TT')
plt.show()
本文链接:https://www.f2er.com/3103951.html

大家都在问