我正在嘗試在 python 中回圈圖例。這是我的代碼。
for i in range(int(np.sqrt(n))):
x=list(df_vrp.iloc[sol[i],1])
y=list(df_vrp.iloc[sol[i],2])
plt.plot(x,y)
plt.legend("Truck" str(i 1),loc='upper left')
但是,結果如下所示。為什么圖例不能回圈并且只顯示一個字母?

uj5u.com熱心網友回復:
我認為這是因為,plt.legend需要一個iterable名字,所以為什么不試試這個......
legend=[]
for i in range(int(np.sqrt(n))):
x=list(df_vrp.iloc[sol[i],1])
y=list(df_vrp.iloc[sol[i],2])
plt.plot(x,y)
legend.append(f"Truck{i 1}")
plt.legend(legend,loc='upper left')
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/412111.html
標籤:
上一篇:RE將每個單詞與模式的一部分匹配
下一篇:如何根據行值將函式應用于資料框
