Avijit Dasgupta
Avijit Dasgupta

Reputation: 2065

Filled plot in matplotlib

I have a set of points like this:

x_axis = np.arange(0, 100)

and

y_axis = np.zeros(100)
y_axis[17 : 23] = 1.

Now, I am plotting this data with the following code:

plt.figure(figsize=(50,1))
plt.fill_between(x_axis, 0, y_axis, color='blue', alpha=.25)

But I am getting the following image:

enter image description here

As the fill_between expects corner of a polygon this is expected. I want to plot a filled square between 17 to 23. How do I achieve this instead of a trapezium?

Upvotes: 0

Views: 81

Answers (1)

Tim Maier
Tim Maier

Reputation: 51

Is step argument helping you ? You can set it to "pre" or "post".

plt.fill_between(x_axis, 0, y_axis, color='blue', alpha=.25, step="pre")

Upvotes: 1

Related Questions