2017-10-07 5 views
0

行列をプロットして、4列のnH.T行列をプロットします。だから私は伝説を作りたい、各列はリストlatent_prot2からの名前を持っています。行列の1つの列から来る各行プロットの凡例エントリを作成します。

latent_prot2 = np.array(["A","B","C","E"]) 

ax3 = plt.subplot2grid((3, 4), (2, 0), colspan=3, rowspan=1) 
ax3.plot(nH.T, label=[n for i,n in enumerate(latent_prot2)]) 
plt.legend() 

各行にはすべてのリストが印刷されています。

enter image description here

私はax3.plot(nH.T, label=[n[i] for i,n in enumerate(latent_prot2)])を試してみましたかplt.legend(label=latent_prot2)への最後の行を変更しますが、彼らは動作していません。凡例の列から各列データの名前をリストから書き出す方法は? forループを経由する必要はありませんが、それが可能かどうかはわかりません。

+0

ああ感謝:

は、凡例を操作するには、legendコールに

ax.legend(labels=["A","B","C","E"]) 

完全な例を要素のリストを渡します。私はそれを転置した、申し訳ありません。 – Jan

答えて

1

plotlabel引数を使用すると、プロットされた曲線ごとに同じラベルが表示されます。

import matplotlib.pyplot as plt 
import numpy as np 

a = np.cumsum(np.cumsum(np.random.randn(15,4), axis=0), axis=1) 

lab = np.array(["A","B","C","E"]) 

fig, ax = plt.subplots() 
ax.plot(a) 
ax.legend(labels=lab) 

plt.show() 

enter image description here

関連する問題