- 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
How to shade the regions between the curves in Matplotlib?
To shade the regions between curves, we can use the fill_between() method.
Steps
Initialize the variable n. Initiliize x and y data points using numpy.
Create a figure and a set of subplots, fig and ax.
Plot the curve using plot method.
Use fill_between() method, fill the area between the two curves.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True n = 256 X = np.linspace(-np.pi, np.pi, n, endpoint=True) Y = np.sin(2 * X) fig, ax = plt.subplots() ax.plot(X, Y, color='blue', alpha=1.0) ax.fill_between(X, 0, Y, color='blue', alpha=.2) plt.show()
Output
- Related Articles
- Find the area between two curves plotted in Matplotlib
- Plot curves to differentiate antialiasing in Matplotlib
- Plot curves in fivethirtyeight stylesheet in Matplotlib
- How to shade points in a scatter based on colormap in Matplotlib?
- How to plot scatter masked points and add a line demarking masked regions in Matplotlib?
- How to change the spacing between ticks in Matplotlib?
- How to increase the spacing between subplots in Matplotlib with subplot2grid?
- Finding the number of regions in the graph
- How to adjust the space between legend markers and labels in Matplotlib?
- What are the polar regions?
- How to add curves to a Rectangle using FabricJS?
- The places where the sun does not rise for six months and does not set for the other six months are(a) polar regions(b) equatorial regions(c) northern regions(d) southern regions
- How to change the separation between tick labels and axis labels in Matplotlib?
- V Curves and Inverted V Curves of Synchronous Motor
- OpenCV Python – How to draw curves using Mouse Events?

Advertisements