我正在運行模擬200次並將3個輸出列表繪製爲3行高透明度。這允許我顯示模擬之間的差異。Pyplot:僅顯示圖例中的前3行
問題是我的圖例顯示3x200項目,而不是3項。我怎樣才能讓它爲每一行顯示圖例?
for simulation in range(200):
plt.plot(num_s_nodes, label="susceptible", color="blue", alpha=0.02)
plt.plot(num_r_nodes, label="recovered", color="green", alpha=0.02)
plt.plot(num_i_nodes, label="infected", color="red", alpha=0.02)
plt.legend()
plt.show()
設置'label = None'也應該有效。 – tacaswell
@tacaswell設置'label = None'實際上是微妙的不同,並且不會從圖例中移除藝術家。例如:'plt.plot([0,1],[0,1],label = None); plt.plot([0,1],[1,0]); plt.legend(['justthislabel'])'會在圖例中顯示兩個項目。用'_nolegend_'替換'None'只能得到一個。 – oLas