0

Okay this might be easy even I search on web but could not get it. Basically i want to add the two different labels to my plot and this is my line of code for that

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")

but I am getting following result in which has same labels for both the plot.as following

enter image description here

Even I tried this

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 

but give the error:

SyntaxError: keyword argument repeated

This link guide for the simple way but here plt.plot()had used twice in the accepted answer.My question is how can i do it the same thing in single line code as I did in my code ?

1 Answer 1

1

You need two lines. One for the plot, one for the legend.

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.