2016-08-09 9 views
2

たとえば、私は2つの曲線を持っています。一つは、実際の曲線であり、他方は、特定のポイントを示すためだけの破線である:(私はこのケースでは、私はちょうどプロット順序を変更することができることを知っている私が最初に凡例を表示したくないMatplotlib:凡例なしで特定の曲線をプロットするにはどうすればよいですか?

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

を)

enter image description here

答えて

3

をこの問題を解決するためにあなたはlabelキーワードを使用してlegend()機能が自動的にラベルを生成させることができます。

enter image description here

:あなたにこの結果を与える

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

関連する問題