'How to force color mapping to a dynamic range larger than the particular input to imshow in matplotlib

Suppose I want to make 2+ heatmaps (on the same, or different Figures) and have the color<->value mapping be the same among them.

By default, the extreme values in the colormap (say jet) will be used for the dynamic range of each heatmap individually (i.e. each call to imshow), and I'd like to force the mapping to be the same, i.e. use the global dynamic range.

I think an equivalent statement is that I'd like to somehow specify an absolute mapping, whereas the behavior of imshow given a cmap object, is relative to the dynamic range of the input.



Solution 1:[1]

If you don't want to specify the ranges but somehow you know that one plot has the largest range, you can get that range with Axesimage.properties()['clim'] and set it for the other plots as I explained here: Imshow subplots with the same colorbar

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community