Home > Software engineering >  Getting the names of colors from matplotlib colormap object
Getting the names of colors from matplotlib colormap object

Time:04-07

I want to get english names of colors from a colormaps object. So far I read that you can get numeric values of colors. For example -

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap

viridis = cm.get_cmap('viridis', 12)
print(viridis)
print(viridis(0.56))

OUTPUTS

<matplotlib.colors.ListedColormap object at 0x7fb112c73ba8>

(0.119512, 0.607464, 0.540218, 1.0)

It is also clear that LineSegColor is a tuple that matches a string and a dict containing a hash between strings and matrices. Matrices are representing a gradient in some n*m space for the expression of particular color.

cdict1 = {'red':   ((0.0, 0.0, 0.0),
                    (0.5, 0.0, 0.1),
                    (1.0, 1.0, 1.0)),

          'green': ((0.0, 0.0, 0.0),
                    (1.0, 0.0, 0.0)),

          'blue':  ((0.0, 0.0, 1.0),
                    (0.5, 0.1, 0.0),
                    (1.0, 0.0, 0.0))
          }
    blue_red1 = LinearSegmentedColormap('BlueRed1', cdict1)

How to reverse engineer the creation of color to Virdis?

Here are few links I visited -

  • comparing colormaps

  • Related