- 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
How can I cycle through line styles in Matplotlib?
To plot multiple lines in a diagram, we can use the cycler that could help to set a new color from the given list of colors. (Here, ‘r’ => ‘red’, ‘g’ => ‘green’, ‘y’ => ‘yellow’, ‘b’ => ‘blue’).
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.
The 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.
import matplotlib.pyplot as plt from cycler import cycler 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()
- How can I draw inline line labels in Matplotlib?
- How can I rotate xtick labels through 90 degrees in Matplotlib?
- How can I create a stacked line graph with matplotlib?
- How can I make a simple 3D line with Matplotlib?
- How can I draw a scatter trend line using Matplotlib?
- How to cycle through both colours and linestyles on a matplotlib figure?
- How can I create custom button in Android using XML Styles?
- Can I give a border to a line in Matplotlib plot function?
- How can I show figures separately in Matplotlib?
- How can I plot hysteresis threshold in Matplotlib?
- How can I iterate through two lists in parallel in Python?
- How can I plot a confusion matrix in matplotlib?
- How can I hide the axes in Matplotlib 3D?
- How do I find the intersection of two line segments in Matplotlib?
- How can I loop through all rows of a table in MySQL?