VOOZH about

URL: https://www.geeksforgeeks.org/python/matplotlib-colors-to_rgba-in-python/

⇱ Matplotlib.colors.to_rgba() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Matplotlib.colors.to_rgba() in Python

Last Updated : 12 Jul, 2025

Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
 

matplotlib.colors.to_rgba()


The matplotlib.colors.to_rgba() function is used convert c(color) to an RGBA color. It converts the color name into an array of RGBA encoded colors. It returns an RGBA tuple of four floats from 0-1.
 

Syntax: matplotlib.colors.to_rgba(c, alpha=None)
Parameters: 
 

  • c: It is a matplotlib color or a np.ma.masked color. 
     
  • alpha: It is an optional parameter that accepts a scalar. It forces the alpha value if alpha is not None. But if c is "none"(case-sensitive) it maps to (0, 0, 0, 0). 
     


Returns: It returns a tuple of scalars in the form of (r, g, b, a). 
 


Example 1: 
 

Output: 
 

👁 matplotlib.colors.to_rgba()


Example 2: 
 

Comment