- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Using Colormaps to set the color of line in Matplotlib
First, we can create a list of colors, and then, we can use the colors while plotting a line in a loop.
Return evenly spaced numbers over a specified interval, store in x.
Update x for four lines and get another variable for evenly_spaced_interval.
Make a list of colors.
Iterate color and set color for all the lines.
To show the figure, use plt.show() method.
from matplotlib import pyplot as plt, cm import numpy as np x = np.linspace(0, 10, 100) lines = [x, x+10, x+5, x+11] evenly_spaced_interval = np.linspace(0, 1, len(lines)) colors = [cm.rainbow(x) for x in evenly_spaced_interval] for i, color in enumerate(colors): plt.plot(lines[i], color=color) plt.show()
- How to customize the color and colormaps of a Plot in Matplotlib
- How to change the color of a line using radiobuttons in Matplotlib?
- How to set a line color to orange, and specify line markers in Matplotlib?
- How to view all colormaps available in Matplotlib?
- How to vary the line color with data index for line graph in matplotlib?
- How to plot a gradient color line in matplotlib?
- How to change the plot line color from blue to black in Matplotlib?
- How to show two different colored colormaps in the same imshow Matplotlib?
- How to set the background color of a column in a matplotlib table?
- How to set the border color of the dots in matplotlib's scatterplots?
- Set the color of the four borders using CSS
- Set the color of the right border using CSS
- How do I set color to Rectangle in Matplotlib?
- How to set the fill color of Ellipse using FabricJS?
- How to change the face color of a plot using Matplotlib?