Reputation: 12791
Say I have the following plot:
x = array([ 40, 60, 80, 100, 120, 138, 160, 200, 240])
y = array([ 6, 5, 11, 6, 6, 0, 2, 1, 3])
plt.figure()
plt.step(x, y, where='mid')
plt.show()
How can I make the same plot so that the blue line starts and ends from the axis y=0 ?
Upvotes: 2
Views: 142
Reputation: 121
You just need to add null values at the beginning and the end of your list y
, and update the axis x
:
y_bottom = [0] + y + [0]
x_bottom = [x[0]] + x + [x[-1]]
and then plot the same way:
plt.figure()
plt.step(x_bottom, y_bottom, where='mid')
plt.show()
Upvotes: 3