Skip to content

Instantly share code, notes, and snippets.

@theodoregoetz
Last active May 25, 2017 18:21
Show Gist options
  • Save theodoregoetz/e2fd3384c5253d55d23453946b1e4999 to your computer and use it in GitHub Desktop.
Save theodoregoetz/e2fd3384c5253d55d23453946b1e4999 to your computer and use it in GitHub Desktop.
colormap testing using sine-wave comb data.
"""
This function produces an image that can be used to
quickly determine the perceptual linearity of a colormap.
The idea behind this came from Peter Kovesi and
explained very well on his website:
http://peterkovesi.com/projects/colourmaps/
CET Perceptually Uniform Colour Maps
Peter Kovesi
Geophysics & Image Analysis Group
Centre for Exploration Targeting
School of Earth and Environment
The University of Western Australia
peter.kovesi@uwa.edu.au
and also on the paper arXiv:1509.03700 found here:
https://arxiv.org/abs/1509.03700
"""
def cmap_comb(ax, cmap):
nperiods, npoints, amplitude = 80, 50, 70
x = np.linspace(0, nperiods * 2 * np.pi, npoints * nperiods)
y = np.linspace(0, amplitude, npoints * 10)
X, Y = np.meshgrid(x, y)
img = X + Y * np.sin(X) * (Y**2 / Y.max()**2)
ax.imshow(img, cmap=cmap, aspect=2, origin='lower', vmin=x[0], vmax=x[-1])
ax.set_title(cmap.name)
ax.set_axis_off()
fig, ax = pyplot.subplots(3, figsize=(12,4*3))
cmap_comb(ax[0], cm.viridis)
cmap_comb(ax[1], cm.jet)
cmap_comb(ax[2], cm.seismic)
@theodoregoetz
Copy link
Author

This is a convenient way to test the perceptual-linearity of a colormap. The comb structure should fade out at the same horizontal level throughout the colormap's range. The depth of the comb is less important than the uniformity of where it gets washed out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment