Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading