2

Matplotlib's colormaps do not provide the HiLo colormap for images, which is often used in microscopy. HiLo shows a gray-level gradient from low to high values, but values at the low-end are shown in blue and ones at the upper end in red.

How can one get this color-map for matplotlib images?

stevosn
  • 463
  • 1
  • 5
  • 12

1 Answers1

5

To achieve this one can use the 'set_under' and 'set_over' methods of the LinearSegmentedColormap class, of which the colormaps are inherited.

# minimal example
from matplotlib import cm
import matplotlib.pyplot as plt
from numpy import arange

im_array = arange(0, 256)

cmap = cm.gray
cmap.set_over(color='red')
cmap.set_under(color='blue')

fig = plt.figure()
ax = fig.add_subplot(111)

vmin = im_array.min() + 1
vmax = im_array.max() - 1

ax.imshow(im_array.reshape((16, 16)), cmap=cmap, vmin=vmin, vmax=vmax)

HiLo example

May be this helps someone. Cheers! S

stevosn
  • 463
  • 1
  • 5
  • 12