Home > OS >  matplotlib fill in between step function
matplotlib fill in between step function

Time:06-04

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

CodePudding user response:

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

  • Related