- 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 plot a multi-colored line, like a rainbow using Matplotlib?
To plot multi-colored lines, like a rainbow, we can create a list of seven rainbow colors (VIBGYOR).
Steps
Create x for data points using numpy.
Create a list of colors (rainbow VIBGYOR).
Iterate in the range of colors list length.
Plot lines with x and y(x+i/20) using plot() method, with marker=o, linewidth=7 and colors[i] where i is the index.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-1, 1, 10) colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"] for i in range(len(colors)): plt.plot(x, x+i/20, c=colors[i], lw=7, marker='o') plt.show()
Output
- Related Articles
- How to plot a rainbow cricle in matplotlib?
- How to animate a line plot in Matplotlib?
- How to plot a smooth line with matplotlib?
- How can I make a scatter plot colored by density in Matplotlib?
- How to plot a 3D continuous line in Matplotlib?
- How to plot a gradient color line in matplotlib?
- Adding a line to a scatter plot using Python's Matplotlib
- How to plot a Pandas multi-index dataFrame with all xticks (Matplotlib)?
- How to plot a wav file using Matplotlib?
- How to get a Gantt plot using matplotlib?
- How to plot a dashed line on a Seaborn lineplot in Matplotlib?
- How to plot a line graph from histogram data in Matplotlib?
- How to create a line chart using Matplotlib?
- How to plot a line (polygonal chain) with matplotlib with minimal smoothing?
- How to draw an average line for a scatter plot in MatPlotLib?

Advertisements