Alines Webマガジン

perceptual color maps in matplotlib for oceanography scipy 2015 kristen thyng XjHzLUnHeM0

📅 October 29, 2026📖 Verified Publication
```html Perceptual Color Maps in Matplotlib for Oceanography — The Complete Guide

Perceptual Color Maps in Matplotlib for Oceanography: A Complete Guide to Scientific Visualization

Choosing the right colormap is one of the most consequential decisions a data scientist or oceanographer makes when producing publication-quality figures. Since Kristen Thyng's acclaimed 2015 SciPy talk—widely viewed and frequently cited—scientists across disciplines have reconsidered their default color choices. This article examines why perceptual color maps matter, what the major options offer, and how oceanography and geoscience communities can make better visualization decisions.

Key Takeaways

  • Avoid rainbowcolormaps.They introduce false edges, compress important data ranges, and render poorly for color-blind readers.
  • Use perceptually uniformcolormaps.Viridis, Twilight, and related maps preserve data fidelity across the full dynamic range.
  • Matplotlib ships with excellent perceptual options.No external library is required—matplotlib.pyplot.get_cmap('viridis') works out of the box.
  • Oceanography benefits from direction-awaremaps.Bidirectional diverging colormaps like Oceanand Landencode both magnitude and sign meaningfully.
  • Color blindness is non-negotiable.Roughly 8% of men and 0.5% of women have some form of color vision deficiency; inclusive maps benefit everyone.

Why Colormap Choice Matters

The Human Visual System Is Not Linear

Our eyes do not perceive equal numerical steps as equal visual steps. A colormap that maps data linearly onto hue and brightness will either saturate certain regions or hide critical variations in others. Perceptually uniform colormaps compensate for this nonlinearity by distributing visual changes evenly across the data range.

Science Reproducibility Depends on Accurate Encoding

When a colormap distorts the relationship between data values and their visual representation, readers may draw incorrect conclusions from the same figure. Peer-reviewed journals increasingly require that figures be interpretable without color—for print, for accessibility, and for reproducibility.

The RainbowColormapProblem

The classic rainbow (or jet) colormap has dominated scientific visualization for decades. It introduces several well-documented artifacts:

  • Fake edges:Sudden hue shifts (e.g., green-to-yellow) create artificial boundaries where none exist in the data.
  • Information loss:Bright yellow regions compress large data ranges into tiny visual spaces, while dark regions expand others.
  • Inaccessibility:Red-green distinctions disappear for the most common form of color blindness (deuteranopia).
  • Printing failures:Many rainbow maps lose all meaning in grayscale.

Major PerceptualColormapOptions

Viridis — The Default Standard

Introduced: Matplotlib 1.5 (2015)
Type: Monotonic sequential
Best for: General-purpose scalar fields, temperature maps, elevation data

Viridis was designed by Eric Klukas, Paul Tol, and Nathaniel Smith specifically for matplotlib. It progresses from dark purple through blue and green to bright yellow, with perceptual uniformity guaranteed at every step. It is now matplotlib's default colormap and is the safest first choice for most oceanographic visualizations.

Twilight — Direction-Aware Sequential

Type: Sequential, perceptually uniform
Best for: Temperature gradients, salinity profiles, current velocity magnitude

Twilight moves from deep blue through neutral gray to warm orange, providing strong directional sense without implying a diverging structure. It is particularly effective for ocean surface temperature maps where the eye naturally associates blue with cold and orange with warm.

RdBu_r and Other Diverging Maps

Type: Diverging (red-white-blue)
Best for: Anomaly maps, deviation from mean, velocity direction

When data contains both positive and negative values relative to a meaningful zero (e.g., sea surface height anomalies, temperature departures from climatology), diverging colormaps encode both magnitude and sign. The reversed variant (rdBu_r) places cool colors at the low end and warm colors at the high end, matching natural expectations.

Ocean and Land — Specialized DivergingMaps

Type: Diverging, perceptually uniform
Best for: Bathymetry, topography, ocean-atmosphere interaction

These specialized colormaps were designed specifically for Earth sciences. "Ocean" transitions from deep navy through cyan to pale blue, mimicking water depth perception. "Land" moves from dark brown through tan to light green, suggesting terrestrial elevation. They are not in matplotlib's standard palette but are widely adopted in the oceanography community.

Plasma and Inferno — High-Contrast Alternatives

Type: Monotonic sequential, high contrast
Best for: Low-light presentations, high-dynamic-range data

Plasma and Inferno offer stronger contrast than Viridis at the cost of some perceptual uniformity. They excel in conference presentations where projectors may wash out subtle color differences, and for visualizing data with extreme value ranges.

Comparison Table: Colormap Options for Oceanography

Colormap Type Perceptually Uniform Color-Blind Safe Grayscale Print Oceanography Fit
Viridis Sequential Yes Yes Good Excellent — default choice
Twilight Sequential Yes Yes Good Very Good — intuitive warm/cool
RdBu_r Diverging No Partial Fair Good for anomalies
Plasma Sequential Near-uniform Yes Excellent Very Good — high contrast
Inferno Sequential Near-uniform Yes Excellent Very Good — dramatic range
Jet / Rainbow Sequential No No Poor Avoid
Ocean Diverging Yes Yes Good Excellent — domain-specific
Land Diverging Yes Yes Good Excellent — topography

How to Implement PerceptualColormaps in Matplotlib

BasicUsage