- 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 fill rainbow color under a curve in Python Matplotlib?
To fill rainbow color under a curve in Python Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a user-defined method, plot_rainbow_under_curve(), that could have a list of 7 rainbow colors and create a set of data points "x" using numpy.
- Iterate in the range of 0 to 7 and plot the curve and fill the area between that curve.
- 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 def plot_rainbow_under_curve(): rainbow_colors = ['violet', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red'] x = np.linspace(-5, 5, 100) for i in range(0, 7): plt.plot(x, x ** 2, lw=0) plt.fill_between(x, x ** 2 + len(rainbow_colors)-i,color=rainbow_colors[i]) plot_rainbow_under_curve() plt.show()
Output
It will produce the following output
- Related Articles
- How to fill color below a curve in Matplotlib?
- Fill the area under a curve in Matplotlib python on log scale
- How to fill color above the curve in Matplotlib Program?
- How to fill the area under a step curve using pyplot? (Matplotlib)
- How to fill the area under a curve in a Seaborn distribution plot?
- How to plot a rainbow cricle in matplotlib?
- How to draw a precision-recall curve with interpolation in Python Matplotlib?
- How to animate a sine curve in Matplotlib?
- How to add a cursor to a curve in Matplotlib?
- How to curve text in a polar plot in matplotlib?
- Linear gradient with rainbow color
- How to remove a specific line or curve in Matplotlib?
- How to plot a multi-colored line, like a rainbow using Matplotlib?
- How to fill an area within a polygon in Python using matplotlib?
- How to change the curve using radiobuttons in Matplotlib?

Advertisements