私は次のデータセットを持っています。たとえば、1、2、またはそれらすべてのバーチャットをプロットするxdata=[0]
必要ydata=[1000]
がxlabels=['first']
あります。バー幅を 0.45 に制限しますか?
ydata=[1000,250,3000,500,3200,4000,2000]
xlabels=['first','sec','third','fourth','fifth','sixth','seventh']
barwidth = 0.45
import matplotlib.pyplot as plt
def create_bar_plot(entries):
assert entries > 0
xdata = range(entries)
xlabels=xlabels[:entries]
xdata=xdata[:entries]
ydata=ydata[:entries]
figure = plt.figure(figsize = (12,6), facecolor = "white")
ax = figure.add_subplot(1,1,1)
plt.grid(True)
if xdata and ydata:
ax.bar(xdata, ydata, width=barwidth,align='center',color='blue')
ax.set_xlabel('categories',color='black')
ax.set_ylabel('duration in minutes',color='black')
ax.set_title('duration plot created ')
ax.set_xticks(xdata)
ax.set_xticklabels(xlabels)
figure.autofmt_xdate(rotation=30)
plt.show()
私が試したとき
create_bar_plot(5)
私はこの数字を手に入れました
でも電話したら
create_bar_plot(1)
私はこの太い棒を手に入れます
では、固定幅の各バーをプロットに表示するにはどうすればよいでしょうか? 期待どおりに動作しないようです..何かが足りない可能性が非常に高いwidth=barwidth
です..bar()
助けてください