Reputation: 1363
For example. I have two curves. One is the real curve and the other is just a dashed line to indicate an specific point:
import matplotlib.pyplot as plt
x2=[0,0.5,0.5]
y2=[0.5,0.5,0]
plt.plot(x2,y2,ls='dashed')
x1=[0,1]
y1=[0,1]
plt.plot(x1,y1)
plt.legend(['','y1'])
plt.show()
I don't want to show the first legend (I know that in this case I can just change the plot order to solve this problem)
Upvotes: 2
Views: 601
Reputation: 31349
You can use the label
keyword and let the legend()
function generate the labels automatically.
x2=[0,0.5,0.5]
y2=[0.5,0.5,0]
plt.plot(x2,y2,ls='dashed')
x1=[0,1]
y1=[0,1]
plt.plot(x1,y1, label='y1')
plt.legend()
Which gives you this result:
Upvotes: 4