- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 fill the area under a step curve using pyplot? (Matplotlib)
To fill the area under step curve using pyplot, we can take the following steps
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Ceate random data points, x, y1 and y2, using numpy.
- To fill the area under the curve, put x and y with ste="pre", using fill_between() method.
- Plot (x, y1) and (x, y2) lines using plot() method with drawstyle="steps" 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(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x plt.fill_between(x, y1, step="pre", alpha=0.4) plt.fill_between(x, y2, step="pre", alpha=0.4) plt.plot(x, y1, drawstyle="steps") plt.plot(x, y2, drawstyle="steps") plt.show()
Output
- Related Articles
- Fill the area under a curve in Matplotlib python on log scale
- How to fill rainbow color under a curve in Python Matplotlib?
- How to fill the area under a curve in a Seaborn distribution plot?
- How to fill color below a curve in Matplotlib?
- How to fill color above the curve in Matplotlib Program?
- How to fill an area within a polygon in Python using matplotlib?
- How to change the curve using radiobuttons in Matplotlib?
- How to zoom subplots together in Matplotlib/Pyplot?
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- How to add footnote under the X-axis using Matplotlib?
- How to plot sine curve on polar axes using Matplotlib?
- How to animate a sine curve in Matplotlib?
- Draw a parametrized curve using pyplot.plot() in Matplotlib
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How to add a cursor to a curve in Matplotlib?

Advertisements