Reputation: 39213
I'd like to make a stacked area chart but it would increase stepwise, like the stairs plot.
It is a cumulative chart, so a stepwise increase would make more sense.
How can it be done?
Upvotes: 2
Views: 912
Reputation: 80329
plt.stackplot
accepts extra kwargs which are sent to plt.fill_between
. One of those is step='post'
, creating a horizontal line starting with the given value. (In contrast, step='pre'
has the horizontal lines at the height of the ending positions.)
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 6)
y1 = np.random.rand(5) + 1
y2 = np.random.rand(5) + 2
y3 = np.random.rand(5) + 3
plt.stackplot(x, y1, y2, y3, step='post', labels=['A', 'B', 'C'])
plt.xticks(x)
plt.legend()
plt.show()
Upvotes: 2