In matplotlib colormaps are functions that map numbers between 0 and 1 to a 4-tuple that represents the R, G, B and A components of a color. If I have such a colormap, say plt.cm.jet
, is there a way to get the inverse of that function, that is a function that maps the 4-tuple back to the original number between 0 and 1?
Example:
import matplotlib.pyplot as plt
import numpy as np
values = np.random.rand(10, 10) # could be any array
colors = plt.cm.jet(values)
values2 = # ... somehow compute values from colors here
assert values == values2