2016-12-05 4 views
-1

私は図の内外に私の伝説を表示しようとしましたが、まだそれを見ることはできません。それだけで空box.whatの間違った私の伝説は表示されません

p1=plt.plot(np.logspace(-2,1,10), trainsScores, label="train scores") 
p2=plt.plot(np.logspace(-2,1,10), testScores, label="test scores") 
plt.legend([p1, p2], ["Train score", "Test score"], loc='upper center',bbox_to_anchor=(0.5, -0.05), 
fancybox=True, shadow=True, ncol=5) 
plt.xlabel('C') 
plt.ylabel('Score') 
plt.show() 

enter image description here

答えて

2

あなたがコンソールに印刷された警告を取得できませんでしたか?

UserWarning: Legend does not support [<matplotlib.lines.Line2D object at 0x7f7a9a442518>] instances. 

ここに説明があります。 p1およびp2はリストであり、凡例ハンドルとしてリストを渡すことはできません。

>>> print(type(p1)) 
<class 'list'> 

p1p2Line2Dインスタンスを割り当てて、それが動作します。

p1, = plt.plot(np.logspace(-2,1,10), np.random.rand(10), label="train scores") 
p2, = plt.plot(np.logspace(-2,1,10), np.random.rand(10), label="test scores") 
plt.legend([p1, p2], ["Train score", "Test score"], loc='upper center', 
      bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=5) 
plt.xlabel('C') 
plt.ylabel('Score') 
plt.show() 

enter image description here

関連する問題