Matplotlib pyplot.colors()
Last Updated :
12 Jul, 2025
In Python, we can plot graphs for visualization using the Matplotlib library. For integrating plots into applications, Matplotlib provides an API. Matplotlib has a module named pyplot which provides a MATLAB-like interface.
Matplotlib Add Color
This function is used to specify the color. It is a do-nothing function.
| Alias | Color |
|---|
| 'b' | Blue |
| 'r' | Red |
| 'g' | Green |
| 'c' | Cyan |
| 'm' | Magenta |
| 'y' | Yellow |
| 'k' | Black |
| 'w' | White |
We can use this function for various data visualizations and obtain insights from them.
Matplotlib.pyplot.colors()
Below are some examples by which we can add color in Matplotlib.
Plotting a Simple Line with Matplotlib Colors
In this example, a line plot is created using Matplotlib, with data points [1, 2, 3, 4]. The line color is specified as 'green'.
Python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], color="green")
plt.show()
Output:

Plotting Data Points with Red Circular Markers
In this example, a line plot is generated using Matplotlib with data points at coordinates [1, 1], [2, 4], [3, 9], [4, 16]. The points are marked with red circular markers (marker='o'). Here, marker=’o’ represents circle while markerfacecolor is used for specifying color of the point marker.
Python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
plt.plot(x, y, marker='o', markerfacecolor='r')
plt.show()
Output:

Plotting a Line with a Hexadecimal Color
In this example, a line plot is created in Matplotlib, extending from (0, 0) to (1, 1). The line color is defined using the hexadecimal code '#FF5733', representing a shade of orange-red.
Python
import matplotlib.pyplot as plt
plt.plot([3, 4], [6, 4], color='#b717bd')
plt.show()
Output:
plotting a line with hexadecimal color
Plotting a Line with an RGBA Color
In this example, a line plot is rendered using Matplotlib, spanning from x=[0,1,2,3] and y=[0,1,4,9]. The line color is set using RGBA values (1, 0.5, 0.5, 0.5), producing a semi-transparent light pink for the line.
Python
import matplotlib.pyplot as plt
x = [0, 1, 2, 3]
y = [0, 1, 4, 9]
plt.plot(x, y, color=(1, 0.5, 0.5, 0.5)) # RGBA tuple (Red, Green, Blue, Alpha)
plt.show()
Output:
Plotting the line with RGBA color
Explore
Python Fundamentals
Python Data Structures
Advanced Python
Data Science with Python
Web Development with Python
Python Practice