Skip to content

Colormaps

SurfView.js includes a comprehensive set of scientific colormaps for data visualization.

Available Colormaps

Sequential

Best for data with a natural ordering from low to high.

NameDescription
viridisPerceptually uniform, colorblind-friendly
plasmaPerceptually uniform, vibrant
infernoPerceptually uniform, dark to bright
magmaPerceptually uniform, dark purple to yellow
hotBlack to red to yellow to white
coolCyan to magenta

Diverging

Best for data with a meaningful center point.

NameDescription
RdBuRed to white to blue
bwrBlue to white to red
coolwarmCool blue to warm red
seismicBlue to white to red (sharp)
SpectralMulti-hue diverging

Qualitative

Best for categorical data.

NameDescription
jetRainbow (blue to red)
hsvFull hue spectrum
rainbowRainbow colors

Monochrome

Single-hue gradients.

NameDescription
greysBlack to white
bluesWhite to blue
redsWhite to red
greensWhite to green

Using Colormaps

With DataLayer

javascript
import { DataLayer } from 'surfview';

const layer = new DataLayer('activation', data, null, 'viridis', {
  range: [-5, 5]
});

With ColorMappedNeuroSurface

javascript
import { ColorMappedNeuroSurface } from 'surfview';

const surface = new ColorMappedNeuroSurface(
  geometry,
  null,
  data,
  'plasma'
);

Changing Colormaps

javascript
// For DataLayer
layer.setColorMap('hot');
surface.updateColors();

// For ColorMappedNeuroSurface
surface.setColorMap('inferno');

Custom Colormaps

From Color Array

javascript
import { ColorMap } from 'surfview';

const customMap = new ColorMap([
  [0, 0, 1],    // blue (low)
  [0, 1, 0],    // green (mid)
  [1, 1, 0],    // yellow
  [1, 0, 0]     // red (high)
], {
  range: [0, 100]
});

Get Available Maps

javascript
import { ColorMap } from 'surfview';

const mapNames = ColorMap.getAvailableMaps();
console.log(mapNames);
// ['viridis', 'plasma', 'inferno', 'magma', 'hot', ...]

Data Range and Thresholding

Setting Range

The range determines how data values map to colors.

javascript
const layer = new DataLayer('stats', data, null, 'RdBu', {
  range: [-3, 3]  // values outside this range are clamped
});

// Update range dynamically
layer.setRange([-5, 5]);
surface.updateColors();

Thresholding

Values inside the threshold range become transparent.

javascript
const layer = new DataLayer('activation', data, null, 'hot', {
  range: [-10, 10],
  threshold: [-2, 2]  // values between -2 and 2 are transparent
});

// Update threshold dynamically
layer.setThreshold([-1, 1]);
surface.updateColors();

Colormap Tips

  1. Use perceptually uniform maps (viridis, plasma) for accurate data representation
  2. Avoid jet for quantitative data - it creates artificial boundaries
  3. Use diverging maps (RdBu, coolwarm) when zero or center is meaningful
  4. Consider colorblindness - viridis and cividis are colorblind-friendly
  5. Match the data - sequential for ordered data, diverging for +/- data

Released under the MIT License.