- 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 cycle through both colours and linestyles on a matplotlib figure?
To cycle through both colors and linestyles on a matplotlib figure, we can take the following steps.
Steps
Set the figure size and adjust the padding between and around the subplots.
Set the current rcParams, withcolors and linestyle.
Plot the data points using plot() method.
To display the figure, use Show() method.
Example
import matplotlib.pyplot as plt from cycler import cycler # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Set the rcParams with color or linestyle plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) + cycler('linestyle', [':', '-.', '-', '--']))) # Plot the data points plt.plot([0, 5, 2, 1]) plt.plot([2, 6, 3, 1]) plt.plot([3, 8, 5, 1]) plt.plot([4, 9, 0, 3]) plt.show()
Output
It will produce the following output −
- Related Articles
- How can I cycle through line styles in Matplotlib?
- How to position and align a Matplotlib figure legend?
- How to get alternating colours in a dashed line using Matplotlib?
- How should I pass a matplotlib object through a function; as Axis, Axes or Figure?
- How to retrieve XY data from a Matplotlib figure?
- How to set the margins of a Matplotlib figure?
- How to add a 3d subplot to a matplotlib figure?\n
- Change figure size and figure format in Matplotlib
- How to plot 4D scatter-plot with custom colours and cutom area size in Python Matplotlib?
- How to set "step" on axis X in my figure in Matplotlib Python 2.6.6?
- Populating Matplotlib subplots through a loop and a function
- How to set the current figure in Matplotlib?
- How does a cycle stop on applying brakes?
- How to convert Matplotlib figure to PIL Image object?
- How to close a Python figure by keyboard input using Matplotlib?

Advertisements