Make filled polygons between two curves in Python using Matplotlib
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
To create filled polygons between two curves a PolyCollection filling needs to be created between y1 and y2.
Parameters for the above task:
- x: It is an array of length N that holds data of x.
- y1: It is an array or a scalar of length N that holds data of y.
- y2:It is an array or a scalar of length N that holds data of y.
Example:
Python3
import matplotlib.pyplot as plt
import numpy as np
width = 3.5
height = 2.5
depth = 65
plt.figure(figsize = (width, height), dpi = depth)
x = [ 1 , 3 , 6 ]
y1 = [ 2 , 3.5 , 4 ]
y2 = [ 3 , 4 , 5.5 ]
plt.fill_between(x, y1, y2)
plt.show()
|
Output:
Last Updated :
06 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...