- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the area between two curves plotted in Matplotlib
To find the area between two curves plot in matplotlib, we can take the following steps
- Set the figure size and adjust the padding between and around the subplots.
- Create x, c1 and c2 data points using numpy.
- Plot (x, c1) and (x, c2) using plot() methods.
- Fill the area between the two curves, c1 and c2, with grey color and hatch "|", using fill_between() method.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 1, 100) c1 = x ** 2 c2 = x plt.plot(x, c1) plt.plot(x, c2) plt.fill_between(x, c1, c2, color="grey", alpha=0.3, hatch='|') plt.show()
Output
- Related Articles
- How to shade the regions between the curves in Matplotlib?
- Plot curves in fivethirtyeight stylesheet in Matplotlib
- Shading an area between two points in a Matplotlib plot
- Plot curves to differentiate antialiasing in Matplotlib
- How to set label for an already plotted line in Matplotlib?
- How to color the plotted area of a JavaFX xy-chart?
- How can multiple plots be plotted in same figure using matplotlib and Python?
- Fill between two vertical lines in matplotlib
- Drawing lines between two plots in Matplotlib
- How to pick a new color for each plotted line within a figure in matplotlib?
- Ratio between the sides of two squares is 2: 5: find the ratio between their perimeter and area
- Program to calculate the area between two Concentric Circles in C++?
- V Curves and Inverted V Curves of Synchronous Motor
- How do I find the intersection of two line segments in Matplotlib?
- How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?

Advertisements