用曲线的精确值标记曲线

2024-05-02 12:33:49 发布

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

enter image description here在下面的代码中,我们在一个图中绘制10条曲线if Ju<11: 怎样才能在每一条曲线上写下,让读者找出每一行是为哪一条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, z, n, 1, 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()

需要帮忙吗


Tags: inforifnpplt曲线listet
1条回答
网友
1楼 · 发布于 2024-05-02 12:33:49

您可以使用来自matplotlibtext(x,y,s)函数。以下是文档: https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.text.html

text接受3个主要参数,x&y这是文本的坐标。和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, z, n, 1, 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, y, s)
                    else:
                        pass
ax1.title.set_text('Fig1')
plt.xlabel('Un')
plt.ylabel('TT')
plt.show()

你还可以试着把它当作传说。您可以通过使用ax.plot()中的label参数为每一行设置一个标签来设置图例。 像这样:

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, z, n, 1, 0))
                        uf_list.append(uf)  
                        ax1.plot(uf_list, 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()

相关问题 更多 >