绘制多条线,但不是全部显示在图表中

2024-06-28 11:08:15 发布

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

我有点奇怪。我试图绘制几行,它显示了图例中的所有绘图,但缺少一行。怎么会这样? 我正在读取一个包含我的数据的文件,这很有效

这是我的密码:

f = open(wk_dir+"/Total_Evaluation.txt","r+")
with open(wk_dir+"/Total_Evaluation.txt","r+") as f1:
    data10 = f1.read()
    data11=data10.replace(","," ")
    TESTDATA = StringIO(data11)
df_eval = pd.read_table(TESTDATA, sep=" ")
df_eval.columns = ["alternativesFound", "alternativesOne","alternativesPenalty","trajectory_amount","resolution","map_name","runtimeAlgo","runtimePathlet","runtimePrePro","runtimeDijkstra","dijkstraLength","runtimeIntersection","runtimeHomotopy","runtimeRTree"]
#ALTERNATIVES FOUND/TRAJEKTORY INPUT EVALUATION
fig, ax = plt.subplots()
x=[]
y1=[]
y2=[]
y3=[]
y4=[]
y5=[]
for i, g in df_eval.groupby('trajectory_amount'):
    foundAlt=df_eval["alternativesFound"].mean()
    y1.append(foundAlt)
    foundMax=df_eval["alternativesFound"].max()
    y2.append(foundMax)
    foundMin=df_eval["alternativesFound"].min()
    y3.append(foundMin)
    foundOne=df_eval["alternativesOne"].mean()
    y4.append(foundOne)
    foundPen=df_eval["alternativesPenalty"].mean()
    y5.append(foundPen)
    x.append(i)
df=pd.DataFrame({'x': x, 'y1': y1, 'y2': y2, 'y3': y3, 'y4': y4, 'y5': y5 })
plt.plot( 'x', 'y1',data=df, marker='o',label="Durchschnittlich gefundene Routen")
plt.plot( 'x', 'y2',data=df, marker='o',label="Minimum gefundener Routen")
plt.plot( 'x', 'y3',data=df, marker='o',label="Maximum gefundener Routen")
plt.plot( 'x', 'y4',data=df, marker='o',label="Durchschnittilch gefundene Routen One-Patching")
plt.plot( 'x', 'y5',data=df, marker='o',label="Durchschnittilch gefundene Routen Penalty")
plt.title("Verhaeltnis von gefundenen alternativen Routen und Groesse des Trajektorieninputs")
plt.legend()
plt.savefig("Alterantives_TrajectoryInput_Evaluation.png")

以下是仅显示4行而不是5行的绘图示例(缺少红色的一行): enter image description here

有人知道这是怎么回事吗?我以这种方式绘制了几个图形,所以在这段代码之后,我有相同的行,只是有不同的变量名


Tags: dfdataplotevalpltmarkerlabelappend