laolux
laolux

Reputation: 1565

matplotlib fill in between step function

I need to plot a step function in matplotlib (because that's the correct interpretation of my data) and would like to fill between the x-axis and the step curve. Something like fill_between, only that this one does not work with drawstyle.

See minimal example below:

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(2)
x = np.arange(50)
y = np.random.rand(50)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y, drawstyle='steps-post')
ax.fill_between(x, y, drawstyle='steps-post')   # does not work
plt.show()

Upvotes: 0

Views: 781

Answers (1)

Z-Y.L
Z-Y.L

Reputation: 1779

You can use ax.fill_between(x, y, step='post'). fill_between doesn't have the parameter of drawstyle.

Upvotes: 3

Related Questions