[英]How to add two different labels to legend for an overlap plot using matplotlib in python?
好吧,即使我在網上搜索但無法獲得它,這可能很容易。 基本上我想將兩個不同的標簽添加到我的情節中,這是我的代碼行
plt.plot(x[:,1],y,'ro',x[:,1],Line_fit,'b',linewidth=0.5,markersize=4,label="training data") # plot the data
plt.legend(loc="upper left")
但我得到以下結果,其中兩個 plot.as 具有相同的標簽
即使我試過這個
plt.plot(x[:,1],y,'ro',x[:,1],Line_fit,'b',linewidth=0.5,markersize=4,label="training data",label="Linear Regression") # plot the data
但給出錯誤:
SyntaxError: keyword argument repeated
你需要兩行。 一為劇情,一為傳奇。
plt.plot(x[:,1], y, 'ro', x[:,1], Line_fit, 'b', linewidth=0.5, markersize=4)
plt.legend(["training data", "Linear Regression"], loc="upper left")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.