- 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 pick a new color for each plotted line within a figure in matplotlib?
To pick a new color for each plotted line within a figure, use the following steps −
Setup X-axis and Y-axis labels for the diagram.
Set the current .rc parameters. For axes facecolor, the group is axes.
Use a cycler to set the color for the group of lines. The color list consists of ‘r’ for red, ‘g’ for green, ‘b’ for blue, and ‘y’ for yellow.
Cycler class helps to create a new Cycler object from a single positional argument, a pair of positional arguments, or the combination of keyword arguments.
Plot the number of lines with different colors.
Use plt.show() to show the figure.
Example
import matplotlib.pyplot as plt from cycler import cycler plt.ylabel("Y-axis ") plt.xlabel("X-axis ") plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']))) plt.plot([0, 5]) plt.plot([2, 6]) plt.plot([3, 8]) plt.plot([4, 9]) plt.show()
Output
- Related Articles
- How to set label for an already plotted line in Matplotlib?
- How to plot a gradient color line in matplotlib?
- How to get the color of the most recent plotted line in Python?
- How to set a line color to orange, and specify line markers in Matplotlib?
- How to vary the line color with data index for line graph in matplotlib?
- How to plot a single line in Matplotlib that continuously changes color?
- How to change the color of a line using radiobuttons in Matplotlib?
- How can multiple plots be plotted in same figure using matplotlib and Python?
- How to color the plotted area of a JavaFX xy-chart?
- How to manually add a legend with a color box on a Matplotlib figure?
- How to Capture a pick event and use it to activate or deactivate Line Plots in Matplotlib
- How to redefine a color for a specific value in a Matplotlib colormap?
- How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?
- How to put a title for a curved line in Python Matplotlib?
- How to change the plot line color from blue to black in Matplotlib?

Advertisements