- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 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.
- Related Articles
- How to change line color in EditText
- How to avoid a new line with a tag?
- How to plot a gradient color line in matplotlib?
- How to set the line color in Python Plotly?
- How to set a line color to orange, and specify line markers in Matplotlib?
- Line colour of a 3D parametric curve in Python's Matplotlib.pyplot
- How to vary the line color with data index for line graph in matplotlib?
- How to change the color of line in xyplot in R?
- How to save an image with matplotlib.pyplot?
- How to remove the space between subplots in Matplotlib.pyplot?
- How to set Line Border color and width with Java?
- How to change the line color in a Seaborn linear regression jointplot?
- 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 to change the plot line color from blue to black in Matplotlib?