Reputation: 195
I'm new to Matplotlib and I'm trying to plot a simple bar chart with the code below
import matplotlib.pyplot as plt
X = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
y = [0.0, 0.0, 0.0, 0.0, 0.8, 0.2, 0.0, 0.0, 0.0, 0.0]
plt.bar(X, y, align='edge', width = 0.8, edgecolor='black')
plt.xticks(X)
plt.show()
I have no idea why I obtain a graph like this. Can anyone help me with it? Thanks.
Upvotes: 1
Views: 1179
Reputation: 2720
Matplotlib is doing exactly as told - plot a bar of height 0.8 and width 0.8 starting at x=0.4 (and therefore occupying space until x=1.2) and one bar of height 0.2, starting at x=0.5 and ranging to x=1.3
This looks odd because a width of 0.8 is excessive for your scale: your data ranges from 0-1, and 0.8 takes up 80% of that, resulting in horizontally stretched bars. Setting the bar width to 0.1 results in a more aesthetically pleasing result
Upvotes: 1