Matplotlib > Custom fill plots

Name
Code
Output
x = [0,1]
y = [0,1]
matplotlib.pyplot.fill_between(x,y)
matplotlib.pyplot.show()

       
           Fill between plot (basic)
       
    
# 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)
       
    
x = [1,2,3,4]
y = [0,1,1,0]
matplotlib.pyplot.fill(x,y)
matplotlib.pyplot.show()

       
           Fill plot (basic)
       
    
# Data
x = numpy.linspace(1,5,100)
y1 = numpy.max(x)**2-x**2
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(x,y1,'red',zorder=1,alpha=0.5)
matplotlib.pyplot.fill(x,y2,'green',zorder=2,alpha=0.5)
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 plot (customized)