Matplotlib > Stack plots

Name
Code
Output
x = [0,1,2,3,4]
y1 = [0,1,1,3,3]
y2 = [0,1,2,3,4]
y3 = [0,2,1,2,2]
matplotlib.pyplot.stackplot(x, y1, y2,y3)
matplotlib.pyplot.show()

       
           Stack plot (basic)
       
    
# Data
x = [0,1,2,3,4]
y1 = [0,1,1,3,3]
y2 = [0,1,2,3,4]
y3 = [0,2,1,2,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)
# set ticks
ax.xaxis.set_ticks(numpy.arange(min(x), max(x)+1, 1.0))
# Plot the data
ax.stackplot(x,y1,y2,y3,labels = ['A','B','C'],colors =['green','red','orange'])
ax.set(title="Plot title", xlabel="x axis", ylabel="y axis")
ax.legend(loc=2)
# Fit the plot layout
matplotlib.pyplot.tight_layout()
# Show the plot
matplotlib.pyplot.show()

       
           Stack plot (customized)