- 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 to avoid line color repetition in matplotlib.pyplot?
To avoid line color repetition in matplotlib.pyplot we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create x and y data points using numpy.
Plot the x and y data points using plot() method.
In the plot() method, use a unique hexadecimal value for the color attribure, for example, color="#980ab5" to set the graph in a unique color. You can also specify a particular color of your choice, for example, color="green".
To display the figure, use show() method.
import numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(1, 100, 1000) y = np.log(x) # Plot the x and y data points with color attribute plt.plot(x, y, color="#980ab5", lw=3) # Display the plot plt.show()
It will produce the following output −
If you run the above code without the color attribute, then the graph will take the default color.
- How to plot a gradient color line in matplotlib?
- How to zoom subplots together in Matplotlib/Pyplot?
- 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?
- Using Colormaps to set the color of line in Matplotlib
- How to change the color of a line using radiobuttons in Matplotlib?
- How to plot a single line in Matplotlib that continuously changes color?
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- How to change the plot line color from blue to black in Matplotlib?
- How can I set the background color on specific areas of a Pyplot figure using Matplotlib?
- How to avoid overlapping error bars in matplotlib?
- How to change line color in EditText
- How do I close all the open pyplot windows (Matplotlib)?
- How to pick a new color for each plotted line within a figure in matplotlib?
- How to make the marker face color transparent without making the line transparent in Matplotlib?