python - Fill between y = 0 and positive values of y -
i'm practicing fill_between matplotlib function.
what want fill area between y = 0 , positive values of y , let area between y = 0 , negative values of y unfilled.
something like:
import matplotlib.pyplot plt x = [1,2,3,4,5] y = [0,2,-3,4,-5] ypos = [i in y if i>0] plt.plot(x,y) plt.fill_between(x,0,ypos) plt.show()
the error gives valueerror: argument dimensions incompatible. i've checked possible solutions couldn't working.
you use
where=np.array(y)>0
to restrict filled region drawn , use
interpolate=true
to have fill_between
find points of intersection:
import numpy np import matplotlib.pyplot plt x = np.array([1,2,3,4,5]) y = np.array([0,2,-3,4,-5]) plt.plot(x,y) plt.fill_between(x, 0, y, where=y>0, interpolate=true) plt.show()
yields
Comments
Post a Comment