- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Darken or lighten a color in Matplotlib
To darken and lighten the color, we can chage the alpha value in the argument of plot() method.Greater the aplha value, darker will be the color.
Steps
- Create data points for xs and ys using numpy.
- Plot two lines with different value of alpha, to replicate darker and lighter color of the lines
- Place legend of the plot using legend() method.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True xs = np.linspace(-2, 2, 100) ys = np.sin(xs) plt.plot(xs, ys, c='red', lw=10, label="Darken") plt.plot(xs+.75, ys+.75, c='red', lw=10, alpha=0.3, label="Lighten") plt.legend(loc='upper left') plt.show()
Output
- Related Articles
- Setting Different Bar color in Matplotlib
- How to fill color below a curve in Matplotlib?
- How to plot a gradient color line in matplotlib?
- Fixing color in scatter plots in Matplotlib
- How to color a Matplotlib scatterplot using a continuous value?
- Changing the color of an axis in Matplotlib
- How to change axes background color in Matplotlib?
- How to change the color of a plot frame in Matplotlib?
- How can I convert numbers to a color scale in Matplotlib?
- How to fill rainbow color under a curve in Python Matplotlib?
- How to redefine a color for a specific value in a Matplotlib colormap?
- How to set the background color of a column in a matplotlib table?
- How to customize the color and colormaps of a Plot 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?

Advertisements