Reputation: 1857
I am using matplotlib to generate a graph. There is one problem while generating bar graph. If there is only one data like shown below,the width of the graph is covering the whole area,evenif the width is set. Example :
x = [3]
y = [10]
bar(x, y, width=0.2,align='center')
Upvotes: 4
Views: 9977
Reputation: 87566
The width
controls the width of the bar in 'data' units. By default the limits of the graph are auto-scaled to your data limits, in this case that is the width of your single bar. You just need the axis limits.
x = [3]
y = [10]
fig, ax = plt.subplots(1, 1)
ax.bar(x, y, width=0.2)
ax.set_xlim(0, 5)
plt.show()
Upvotes: 9