Matplotlib > Fill between plot (customized)

Name
Code
Output
# Data
x = numpy.linspace(0,30,100)
y1 = numpy.sin(x)
#y2 = x**2
# New Figure
fig = matplotlib.pyplot.figure(figsize=(7,4),facecolor='silver')
# New Axes
ax = fig.add_subplot(111,facecolor='azure')
# Add grid
ax.grid(color='b', linestyle='-', linewidth=0.5)
# Plot the data
matplotlib.pyplot.fill_between(x,y1,where=y1>0, facecolor='green', interpolate=True)
matplotlib.pyplot.fill_between(x,y1,where=y1<0, facecolor='red', interpolate=True)
ax.set(title="Plot title", xlabel="x axis", ylabel="y axis") 
# Fit the plot layout
matplotlib.pyplot.tight_layout()
# Show the plot
matplotlib.pyplot.show()

       
           Fill between plot (customized)