TL;DR
I have a RGB image (i.e ndarray of shape (nlines, ncolumns, 3)) whose colors are the ones of the HSV colormap (matplotlib.cm.hsv)
How do I transform such RGB image so that the values correspond to a different colormap?
MORE DETAILS
I have two 2D numpy arrays that represent a phase (in -pi, pi) and magnitude of some data. I want to have the phase values 'modulated' by the magnitude, so I create a matrix with like this:
HSV_matrix[..., 0] = phase_scaled # rescaled in (0,1)
HSV_matrix[..., 1] = np.ones_like(phase_scaled)
HSV_matrix[..., 2] = magnitude_scaled # rescaled in (0,1)
which means that the phase is associated to the HUE and the magnitude to the VALUE.
Then I input such matrix to hsv_to_rgb():
rgb_image = matplotlib.colors.hsv_to_rgb(hsv_matrix)
rgb_image is now a ndarray of shape (nlines, ncolumns, 3) and represent the RGB values of my image where the colors are associated to the phase and the brightness to the magnitude.
At this point the colormap is already defined because, by definition, the values of rgb_image indicate the Red Green and Blue values for every pixel.
After hsv_to_rgb, the colormap of rgb_image is matplotlib.cm.hsv, hence to produce a consistent colorbar:
cmap = cm.ScalarMappable(cmap=cm.hsv, norm=plt.Normalize(vmin=hmin, vmax=hmax))
plt.colorbar(cmap)
where hmin and hmax are the min and max value of whatever I have in my HUE (hsv_matrix[...,0]).
NOTE: Matplotlib imshow ignores the cmap parameter if the input is RGB(A) [1], hence I cannot change the colormap with imshow
[1] https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.imshow.html