2016-04-17 11 views
0
ax3.bar(D, HighC_21, facecolor='g', width=0.8, alpha=1.0, align='edge') 
ax3.bar(D, LowC_21, bottom=HighC_21, color='r', width=0.8, alpha=1, align='edge') 

私はこのコードをx軸のプロットバーに使用していますが、開始点と終了点に不均一なスペースがあります。 x軸にバーを均等に広げるにはどうすればよいですか?matplotlibのバー間のスペースが均一

enter image description here

答えて

1

あなたは、各バーのx位置を指定するpyplot.barへの最初の入力を使用する必要があります。現在、値Dを使用していますので、各xの位置にバーが表示されます(D)。あなたの質問に基づいて、Dの値は、バーが欲しい場所ではありません。

最初の入力を、必要な(均等な間隔の)値に変更する必要があります。 numpy.linspaceで簡単にこれを行うことができます。

import numpy as np 

# Specify where you want the first and last bars as minX and maxX 
x = np.linspace(minX, maxX, len(LowC_21)) 
ax3.bar(x, HighC_21, facecolor='g', width=0.8, alpha=1.0) 
ax3.bar(x, LowC_21, bottom=HighC_21, color='r', width=0.8, alpha=1) 
関連する問題