Extract Matplotlib colormap in hex-format



To extract matplotlib colormap in hex-format, we can take the following steps −

  • Get the rainbow color map.

  • Iterate in the range of rainbow colormap length.

  • Using rgb2hex method, convert rgba tuple to a hexadecimal representation of a color.

Example

from matplotlib import cm import matplotlib cmap = cm.rainbow for i in range(cmap.N):    rgba = cmap(i)    print("Hexadecimal representation of rgba:{} is {}".format(rgba, matplotlib.colors.rgb2hex(rgba)))

Output

............... ........................ .................................... Hexadecimal representation of rgba:(1.0, 0.3954512068705424, 0.2018824091570102, 1.0) is #ff6533 Hexadecimal representation of rgba:(1.0, 0.38410574917192575, 0.1958454670071669, 1.0) is #ff6232 Hexadecimal representation of rgba:(1.0, 0.37270199199091436, 0.18980109344182594, 1.0) is #ff5f30 .........................................................
Updated on: 2021-05-06T13:59:29+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements