2016-04-03 18 views
0

数字の代わりにテキストとしてy軸を使用してラインプロットを作成しようとしていますが、これを試してみましたが、solution y軸には'テキスト'。私は間違って何をしています。 CurrentCoresLEは文字列のリストです。matplotlibを使用したラインプロットの数値の代わりにy軸のテキストを使用

Y_AXIS_VALUES = list(numpy.sort(list(set(CurrentCoresLE)))) 
Y_AXIS = [Y_AXIS_VALUES.index(CurrentCoresLE[i]) for i in range(len(CurrentCoresLE))] 
one = axes4.plot(Y_AXIS, color = '0.2', label='CoresUsed') 
axes4.set_ylabel('Cores') 
#https://stackoverflow.com/questions/17074772/using-text-on-y-axis-in-matplotlib-instead-of-numbers 
#plt.yticks(Y_AXIS, Y_AXIS_VALUES) 
axes4.set_yticks(Y_AXIS, Y_AXIS_VALUES) 
axes4.legend(prop={'size':6}, ncol=4) 
axes4.xaxis.grid(True) 

そして、私はplt代わりのaxes4をしようとすると、それはここにテキストを与えることなく、1箇所のみ でない例である:ここではenter image description here がexmapleのY_AXIS_VALUESとY_AXIS

['0B2S', '0B3S', '0B4S', '1B3S', '2B0S', '2B2S'] 
[4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 0, 1, 0, 1, 1, 0, 0, 1, 2, 1, 2, 2, 1, 0, 1, 2, 2, 1, 0, 1, 2, 1, 1, 2, 2, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 1] 
+0

を使用していたと思います。それから私はあなたを助けることができます。これはあまりにも難しくないようです。 –

+0

Y_AXISとY_AXIS_VALUESの値を確認する必要があります。 – Hun

+0

今のところ、 'ax.set_yticklables(Your_txt_list)'で 'plt.yticks(np.arange(min(Y_value)、max(Y_value)、len(Your_txt_list)))'を使うことができます。これが正しいとは思わない。 –

答えて

0

でこれがどのようにありますそれを私が直した。

axes4 = fig.add_subplot(514) 
Y_AXIS_VALUES = list(numpy.sort(list(set(CurrentCoresLE)))) 
Y_AXIS = [Y_AXIS_VALUES.index(CurrentCoresLE[i]) for i in range(len(CurrentCoresLE))] 
one = axes4.plot(Y_AXIS, color = '0.2', label='CoresUsed') 
axes4.set_ylabel('Cores') 
ytickNames = axes4.set_yticklabels(Y_AXIS_VALUES) 
fontnum = 10 
plt.setp(ytickNames, fontsize=fontnum) 
axes4.legend(prop={'size':6}, ncol=4) 
axes4.xaxis.grid(True) 

私はあなたのデータを表示することができますトリックは、最初yticktabelsを設定し、setp

関連する問題