Josh
Josh

Reputation: 12791

Closing steps in matplotlib

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 ?

enter image description here

Upvotes: 2

Views: 142

Answers (1)

cynddl
cynddl

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()

Figure with lines starting at bottom

Upvotes: 3

Related Questions