2016-08-11 14 views
-1

オブジェクトのシーケンスを表す5つの要素のリストを得ました。要素0は番号1を表し、以下同様である。そのため私は、グラフ上で適切に表現これらの番号を持ってこれをしなければならなかった:グラフの横に隙間があるのはなぜですか? (matplotlib/py)

higher_chances.insert(0, 0) 
plt.xlim(1,len(higher_chances)) 
plt.xticks(range(1, len(higher_chances))) 

だから基本的に、私はそれを無視し、その後、リストの先頭に0を挿入します。

私は今グラフの右側にギャップがあり、それを削除する方法を見つけることができません。任意の助けをいただければ幸いです

enter image description here

リスト:[0、47.0、46.0、45.0、45.0、43.0]

以下のすべてのコード:

# Inset 0 at first index so index 1 reflect sequence of 1 candle 
higher_chances.insert(0, 0) 

# Convert to actual percentages for presentation 
higher_chances = [ elem*100 for elem in higher_chances] 

plt.plot(higher_chances) 
plt.ylim(min(higher_chances[1:]), max(higher_chances[1:])) 
plt.xlim(1,len(higher_chances)) 
plt.xticks(range(1, len(higher_chances))) 

plt.xlabel('Number of consecutive bull candles', fontsize=15) 
plt.ylabel('% chance of another bull candle following', fontsize=15) 

plt.show() 

編集:

他のコードを変更せずにplt.axis('tight')を追加すると、グラフは次のように変わります。

enter image description here

xlim/ylimを取り出してplt.axis('tight')を追加した場合、グラフは上のものと変わりません。

答えて

0

変更:

plt.xlim(1,len(higher_chances)) 

へ:

plt.xlim(1,len(higher_chances)-1) 

enter image description here

しかし、私が追加した場合、-1が最後のラベルを削除し、上記のとおり、それは、あるとして以下を残す:

plt.xticks(range(1, len(higher_chances))) 

enter image description here

関連する問題