dslack
dslack

Reputation: 845

matplotlib: how can I make an opaque filled region that covers what's underneath?

For instance, if I do this:

import numpy as np
import pylab as plt
x = np.linspace(0,10)
y = x**2
z = 50*np.sin(x)
plt.plot(x,y)
plt.fill_between(x,z,facecolor='r')
plt.show()

then the line plot is still visible underneath the shaded region. Is there a way to make the shaded region entirely block what's underneath it?

Thanks.

Upvotes: 3

Views: 639

Answers (1)

unutbu
unutbu

Reputation: 879641

Use zorder:

import numpy as np
import pylab as plt

x = np.linspace(0, 10)
y = x**2
z = 50*np.sin(x)
plt.plot(x, y)
plt.fill_between(x, z, facecolor='r', zorder=3)
plt.show()

enter image description here

Upvotes: 5

Related Questions