Skip to main content

Downsampling

What is downsampling?​

Downsampling (also called subsampling or, for charts, data reduction or resampling) is reducing the number of samples in a dataset, signal or image while keeping what matters about it. In data visualisation it means drawing a smaller, carefully chosen set of points, so a chart of millions of values looks the same but draws far faster.

A noisy signal of 1,000,000 points with twelve sharp spikes, drawn as a line chart in a dark navy theme

A signal of 1,000,000 points with 12 short spikes (sample data), drawn with automatic resampling. Try the interactive version.

Key takeaways
  • A chart can only show as many columns of detail as it has pixels across, so drawing more points than that adds work, not information.
  • Every nth point and averaging are simple but lose or shrink spikes. Min-max, M4 and LTTB keep them.
  • Min-max and M4 keep every peak and the full spread of noise; LTTB keeps the overall shape with fewer points.
  • In signal processing, downsampling needs a low-pass (anti-aliasing) filter first, or fast signals turn into false slow ones.
  • Downsample only for display. Keep the full data for zooming, statistics and alerts.

Why downsample data for a chart?​

Pixels, not points, are the limit. A line chart 1,000 pixels wide has 1,000 columns. Give it 1,000,000 points and about 1,000 of them land in each column. The screen can only show one vertical stroke per column, from the lowest value in it to the highest, so most of those points change nothing you can see.

Drawing them still costs time. Each point has to be sent, transformed to screen coordinates and drawn, every time the chart redraws. With millions of points, that can make zooming, panning and live updates slow, especially in a browser on an ordinary laptop.

Downsampling cuts the points to roughly what the chart can display, typically one to four per pixel column. Done well, the picture doesn't change. Done badly, it hides exactly the events people are looking for.

For the wider picture, including rendering technology and server-side aggregation, see big data visualisation and our blog post How to Visualize Millions of Data Points Efficiently.

What goes wrong with naive downsampling​

The obvious approach is to keep every nth point: with 1,000,000 points and room for 1,000, keep points 1, 1,001, 2,001 and so on. It's fast, and on smooth data it works. On real data it causes two problems.

  • Missed peaks. A spike that lasts one or two samples sits between the points you keep, so it vanishes. In monitoring data, that spike is often the fault, the trade or the heartbeat you needed to see.
  • Aliasing. If the data repeats faster than the gap between kept points, the kept points can trace a slower pattern that isn't really there. The same effect makes wheels look as if they spin backwards on film. See Downsampling in signal processing below.

Averaging each bucket is the next idea. It does better on noise, but it shrinks spikes: a spike of 12 averaged with a neighbour of 5 becomes 8.5, and averaged over a thousand samples it disappears into the line.

Worked example: 12 points down to about 6​

Here is a short series with one spike at point 8, reduced to about half its size by each of the five methods on this page. Points are numbered 1 to 12.

Point123456789101112
Value3435445124343
MethodPoints kept (point: value)Highest value keptSpike
Every 2nd point1: 3, 3: 3, 5: 4, 7: 5, 9: 4, 11: 45Lost
Average of each pair3.5, 4, 4, 8.5, 3.5, 3.58.5Shrunk to 8.5
Min-max, 3 buckets of 41: 3, 4: 5, 5: 4, 8: 12, 9: 4, 10: 312Kept
M4, 3 buckets of 41: 3, 4: 5, 5: 4, 8: 12, 9: 4, 10: 3, 12: 312Kept
LTTB, 6 points1: 3, 2: 4, 6: 4, 8: 12, 9: 4, 12: 312Kept

Six small line charts of the same 12 points. Every second point loses the spike, averaging pairs cuts it from 12 to 8.5, and min-max, M4 and LTTB all keep it

Every method kept about the same number of points. What differs is which points they keep. The methods that look at every value in a bucket (min-max, M4, LTTB) find the spike, and the methods that don't (every nth) or that blend values together (average) lose it.

Downsampling methods for time series​

All five methods below take a series sorted by time (or any x value), split it into buckets, and keep one or more points from each bucket. They differ in which points they keep.

MethodPoints kept per bucketKeeps spikes?Keeps the spread of noise?Best for
Every nth point1 (whichever comes up)NoNoSmooth data, quick previews
Average (bucket mean)1 (the mean)No: shrinks themNo: smooths itTrends, when spikes are noise
Min-max2 (lowest and highest)YesYesMonitoring, signals, finance
M4Up to 4 (first, lowest, highest, last)YesYesExact line charts at a known width
LTTB1 (largest triangle)UsuallyPartlySmaller outputs that keep the shape

Every nth point​

Keep one point in every n, where n is the number of points divided by the target. It needs no maths and almost no time, and on smooth, slowly changing data it looks fine. Anything that happens between the points it keeps is invisible to it, so use it only when the data has no short events, or as a quick preview.

Average (bucket mean)​

Split the data into equal buckets and keep the mean of each. Averaging smooths out random noise, which can help show a trend. It also smooths out spikes, dips and sudden steps, and the result has values that never occurred in the data. Variants keep the median, or the first or last value of each bucket, with similar trade-offs.

Min-max​

Make one bucket per pixel column and keep the lowest and highest point in each, in time order. Since a line chart draws each column as a stroke from its lowest to its highest value, min-max keeps exactly what the screen would show: every peak, every trough and the full thickness of a noisy band. It's fast, needs only one pass over the data, and is the usual choice for oscilloscope-style and monitoring charts. Its output is two points per column, so a 1,000-pixel chart needs about 2,000 points.

M4​

M4, from a 2014 paper by Jugel and colleagues, keeps four points per pixel column: the first, the lowest, the highest and the last. The extra first and last points make the short lines that join one column to the next land in the right place, so the paper shows the reduced line draws the same pixels as the full data at that chart width. It's a stricter version of min-max, at up to twice the points, and is often run inside a database query so only the reduced data leaves the server.

LTTB (Largest-Triangle-Three-Buckets)​

LTTB was described by Sveinn Steinarsson in his 2013 master's thesis at the University of Iceland, and is now widely used in charting and time-series tools. It works like this:

  1. Always keep the first and the last point.
  2. Split the points between them into equal buckets, one per point you want to keep.
  3. Work through the buckets from left to right. In each one, consider the point you kept in the previous bucket (A) and the average of the next bucket (C).
  4. Keep the point B in the current bucket that makes the largest triangle A-B-C. A big triangle means the line turns sharply at B, so peaks, dips and corners win.

LTTB gives a smooth, faithful shape with one point per bucket, half as many as min-max. It has two weaknesses. When a bucket holds both a high spike and a low one, it can keep only one of them; and on dense, noisy data it can understate how wide the noise is, because one point per bucket can't show both its top and its bottom. Each choice depends on the one before, so it runs as a single pass from left to right.

See the methods on a million points​

The chart below has 1,000,000 points: 1,000 samples a second for 1,000 seconds, with 12 spikes that each last one to three samples. The faint blue line is all of the raw data. The orange line is the downsampled copy. Pick a method and a target number of points; the line under the buttons counts how many spikes the orange line still reaches.

Things to try:

  • Every nth at 1,000 points misses every spike. At 5,000 points it catches one, by luck.
  • Average keeps the slow waves but loses the spikes and the noise.
  • Min-max and M4 match the raw line: same spikes, same thickness.
  • LTTB keeps all 12 spikes, with one point per bucket instead of two.
  • Zoom in on a spike (scroll). The orange line was computed once for the full view, so it turns blocky. The blue line stays sharp because the chart library resamples it again for every view. That's why charts should downsample for the current view, not once in advance.

How to choose a downsampling method​

If you need…UseWhy
Every spike and dip, exactly as the full data would drawMin-max or M4They keep each pixel column's extremes, so nothing visible is lost
A small, smooth overview that keeps the shapeLTTBOne point per bucket, chosen to keep turns and peaks
A trend, with noise removed on purposeAverage or a moving averageSmoothing is the goal, not a side effect
A quick preview of smooth dataEvery nth pointFastest, and fine when nothing happens between samples
A lower sample rate for further signal processingAnti-alias filter, then keep every nth (decimation)Removes frequencies that would otherwise alias

Two rules of thumb:

  • Size the target to the chart, not to a round number: about two points per pixel column for min-max, four for M4.
  • Recompute when the view changes. A reduction made for the whole range is too coarse once someone zooms in.

Downsampling in signal processing: decimation and anti-aliasing​

In digital signal processing (audio, sensors, radio), downsampling by a factor M means keeping every Mth sample, which divides the sample rate by M. Recording at 96,000 samples a second and keeping every second sample gives 48,000 samples a second.

Downsampling also lowers the Nyquist limit. A signal sampled at a rate fs can only represent frequencies below fs/2. After downsampling by M, that limit falls to fs/(2M). Any part of the signal above the new limit doesn't disappear. It aliases: it folds back and shows up as a false, lower frequency that can't be told apart from real content.

Two panels: on the left, a slow wave with a fast ripple sampled once a second with no filter, where the samples trace a false wave with the wrong height and timing; on the right, the same signal filtered first, where the samples follow the real slow wave

The fix is to remove those frequencies first, with a low-pass anti-aliasing filter whose cutoff is at or below the new Nyquist limit. Filter, then keep every Mth sample. That two-step process is usually called decimation.

  • Downsampling (or subsampling): keep every Mth sample.
  • Decimation: low-pass filter, then downsample.
  • Upsampling: insert samples between the existing ones and fill them in by interpolation.
  • Changing by a fraction: upsample by L, filter, then downsample by M. For example, 48 kHz to 44.1 kHz is a factor of 147/160.

How is decimation different from chart downsampling?​

Decimation aims to keep a valid, evenly spaced signal for more processing, so it deliberately removes fast content, spikes included. Chart downsampling aims to keep what the eye should see, so it deliberately keeps spikes. Use decimation before analysis, and min-max, M4 or LTTB for display.

Downsampling in images and machine learning​

The word has two other common meanings:

  • Images: reducing an image's resolution, for example from 4000 × 3000 pixels to 800 × 600. Blurring slightly before shrinking plays the role of the anti-aliasing filter; without it, fine patterns turn into moiré. In neural networks, pooling and strided layers downsample feature maps in the same sense.
  • Imbalanced data in machine learning: reducing the number of examples in the majority class, for example keeping a random 5% of normal transactions so they don't swamp the rare fraud cases. The model is then corrected for the changed proportions.

Both share the idea of keeping fewer samples, but the methods on this page are for time series and charts.

Common downsampling mistakes​

  • Using every nth point on spiky data. It's the default in many quick scripts, and it silently hides short events. Use min-max, M4 or LTTB.
  • Running statistics on the downsampled copy. Means, standard deviations, peak counts and thresholds all change. Calculate on the full data, then downsample only to draw.
  • Treating unevenly spaced data as evenly spaced. Buckets by count assume regular sampling. With gaps or bursts, split buckets by time instead.
  • Not telling readers. If a chart shows reduced or smoothed data, say so in the caption or tooltip, especially in reports.

How to downsample data for a chart in JavaScript, React or Angular​

SciChart.js resamples line series automatically for each view, using algorithms that keep every peak and trough, then draws them with WebGL and WebGPU. You pass all the raw points; you don't write any downsampling code. The chart below has 1,000,000 points. Scroll to zoom into a spike, drag to pan, double-click to reset, and hover to see values. Switch resampling to None and the picture stays the same; only the work behind each frame changes.

Here is the code for this chart:

// A line chart with 1,000,000 points. SciChart.js downsamples (resamples) it automatically for each view.
const {
SciChartSurface,
NumericAxis,
FastLineRenderableSeries,
XyDataSeries,
EResamplingMode,
NumberRange,
SciChartJsNavyTheme,
CursorModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"

const { wasmContext, sciChartSurface } = await SciChartSurface.create(divElementId, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "Time (s)", growBy: new NumberRange(0.02, 0.01) }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: "Signal", growBy: new NumberRange(0.08, 0.2) }));

// Pass all the raw data: no downsampling in your code
const { xValues, yValues } = getLargeSignal();
const dataSeries = new XyDataSeries(wasmContext, {
xValues,
yValues,
// Telling SciChart how the data is laid out saves it checking, and lets it pick the fastest resampler
dataIsSortedInX: true,
dataEvenlySpacedInX: true,
containsNaN: false
});

const lineSeries = new FastLineRenderableSeries(wasmContext, {
dataSeries,
stroke: "#50C7E0",
strokeThickness: 1,
// Auto (the default) resamples to the pixels on screen, keeping every peak and trough.
// None draws every point: the same picture, with more work for each frame.
resamplingMode: EResamplingMode.Auto
});
sciChartSurface.renderableSeries.add(lineSeries);

// Hover for values, scroll to zoom, drag to pan, double-click to reset
sciChartSurface.chartModifiers.add(
new CursorModifier({ showTooltip: true }),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier()
);

// Switch resampling on and off to compare
addResamplingButtons(sciChartSurface.domChartRoot, (mode) => {
lineSeries.resamplingMode = mode === "Auto" ? EResamplingMode.Auto : EResamplingMode.None;
});

Key points:

  • Resampling is on by default (resamplingMode: EResamplingMode.Auto). SciChart.js picks an algorithm from the series type and the data, and runs it again whenever the view changes, so zoomed-in views get full detail.
  • Setting dataIsSortedInX, dataEvenlySpacedInX and containsNaN tells SciChart.js how the data is laid out, so it doesn't have to check each time you add data.
  • resamplingPrecision raises the number of points kept per pixel, which can look better on very noisy data at some cost in speed. EResamplingMode.None turns resampling off for one series.
  • Your statistics, exports and alerts still see every raw point: resampling only affects what is drawn.

Downsampling helpers for any chart library​

If your chart library doesn't resample, or you need to reduce data before sending it from a server, these functions implement every method on this page. They're the ones the comparison chart above uses. Each takes sorted x and y arrays and a target number of points, and returns { x, y }.

// Downsampling helpers. Each one takes x and y arrays (sorted by x) and a target number of points,
// and returns a smaller { x, y } to draw. They work with any chart library.

// Every nth point: keep one point in every n. Fast, but blind to anything between the points it keeps.
function everyNth(x, y, target) {
const n = Math.max(1, Math.floor(x.length / target));
const outX = [];
const outY = [];
for (let i = 0; i < x.length; i += n) {
outX.push(x[i]);
outY.push(y[i]);
}
return { x: outX, y: outY };
}

// Average: split the data into equal buckets and keep each bucket's mean. Smooth, but flattens spikes.
function bucketAverage(x, y, target) {
const size = x.length / target;
const outX = [];
const outY = [];
for (let b = 0; b < target; b++) {
const start = Math.floor(b * size);
const end = Math.min(x.length, Math.floor((b + 1) * size));
if (end <= start) continue;
let sumX = 0;
let sumY = 0;
for (let i = start; i < end; i++) {
sumX += x[i];
sumY += y[i];
}
outX.push(sumX / (end - start));
outY.push(sumY / (end - start));
}
return { x: outX, y: outY };
}

// Lowest and highest point in each bucket, by index
function bucketExtremes(y, start, end) {
let iMin = start;
let iMax = start;
for (let i = start + 1; i < end; i++) {
if (y[i] < y[iMin]) iMin = i;
if (y[i] > y[iMax]) iMax = i;
}
return { iMin, iMax };
}

// Min-max: one bucket per two output points (one per pixel column when target = 2 x chart width).
// Keeps each bucket's lowest and highest point, in time order, so every peak and trough survives.
function minMax(x, y, target) {
const buckets = Math.max(1, Math.floor(target / 2));
const size = x.length / buckets;
const outX = [];
const outY = [];
for (let b = 0; b < buckets; b++) {
const start = Math.floor(b * size);
const end = Math.min(x.length, Math.floor((b + 1) * size));
if (end <= start) continue;
const { iMin, iMax } = bucketExtremes(y, start, end);
for (const i of iMin === iMax ? [iMin] : [Math.min(iMin, iMax), Math.max(iMin, iMax)]) {
outX.push(x[i]);
outY.push(y[i]);
}
}
return { x: outX, y: outY };
}

// M4 (Jugel et al., 2014): one bucket per four output points. Keeps each bucket's first, lowest,
// highest and last point, so the lines joining one pixel column to the next are drawn correctly too.
function m4(x, y, target) {
const buckets = Math.max(1, Math.floor(target / 4));
const size = x.length / buckets;
const outX = [];
const outY = [];
for (let b = 0; b < buckets; b++) {
const start = Math.floor(b * size);
const end = Math.min(x.length, Math.floor((b + 1) * size));
if (end <= start) continue;
const { iMin, iMax } = bucketExtremes(y, start, end);
const keep = [...new Set([start, iMin, iMax, end - 1])].sort((p, q) => p - q);
for (const i of keep) {
outX.push(x[i]);
outY.push(y[i]);
}
}
return { x: outX, y: outY };
}

// Largest-Triangle-Three-Buckets (Steinarsson, 2013). Keeps the first and last points, then one point per
// bucket: the one that makes the largest triangle with the point kept before it and the next bucket's average.
function lttb(x, y, target) {
const n = x.length;
if (target >= n || target < 3) return { x: Array.from(x), y: Array.from(y) };
const outX = [x[0]];
const outY = [y[0]];
const every = (n - 2) / (target - 2);
let a = 0; // index of the point kept in the previous bucket
for (let b = 0; b < target - 2; b++) {
// The average point of the next bucket (for the last bucket, the final point)
const nextStart = Math.floor((b + 1) * every) + 1;
const nextEnd = Math.min(n, Math.floor((b + 2) * every) + 1);
let avgX = x[n - 1];
let avgY = y[n - 1];
if (nextEnd > nextStart) {
avgX = 0;
avgY = 0;
for (let i = nextStart; i < nextEnd; i++) {
avgX += x[i];
avgY += y[i];
}
avgX /= nextEnd - nextStart;
avgY /= nextEnd - nextStart;
}
// The point in this bucket with the largest triangle area (twice the area: the factor doesn't matter)
const start = Math.floor(b * every) + 1;
const end = Math.floor((b + 1) * every) + 1;
let best = start;
let bestArea = -1;
for (let i = start; i < end; i++) {
const area = Math.abs((x[a] - avgX) * (y[i] - y[a]) - (x[a] - x[i]) * (avgY - y[a]));
if (area > bestArea) {
bestArea = area;
best = i;
}
}
outX.push(x[best]);
outY.push(y[best]);
a = best;
}
outX.push(x[n - 1]);
outY.push(y[n - 1]);
return { x: outX, y: outY };
}

See it in the demo app: JavaScript 1 million point chart · React 1 million point chart · Angular 1 million point chart

Go deeper: SciChart.js resampling documentation, including the resampling modes and precision, and the performance tips and tricks.

Frequently asked questions​

What does downsampling mean?​

Downsampling means reducing the number of samples in a dataset, a signal or an image while keeping what matters about it. On a chart, it means drawing a smaller set of points chosen so the line looks the same. In signal processing, it means lowering the sample rate, usually after a low-pass filter.

Is downsampling the same as decimation?​

Nearly. In signal processing, downsampling by a factor M keeps every Mth sample, and decimation usually means the full process: a low-pass anti-aliasing filter, then downsampling. Some people use the two words for the same thing, and subsampling is another name for plain downsampling.

What is the difference between upsampling and downsampling?​

Downsampling reduces the number of samples, for example from 1,000 a second to 100 a second. Upsampling increases it, by inserting new samples between the existing ones and filling them in by interpolation. Changing a rate by a fraction, such as 48 kHz to 44.1 kHz, uses both: upsample by 147, then downsample by 160.

How does the LTTB algorithm work?​

Largest-Triangle-Three-Buckets keeps the first and last points, splits the rest into equal buckets, and keeps one point per bucket: the one that forms the largest triangle with the point kept in the previous bucket and the average of the next bucket. Large triangles mean sharp changes, so peaks and turns survive.

Does downsampling lose data?​

The downsampled copy has fewer points, so it holds less information than the original. Good chart downsampling chooses the points so the drawn line looks the same, and keeps the full data for zooming, statistics and export. Never run calculations on the downsampled copy.

How do I downsample data for a chart in JavaScript?​

Either write a helper, such as LTTB or min-max, that reduces your arrays before you pass them to the chart, or use a chart library that resamples for you. SciChart.js resamples line series automatically for each view, so you can pass millions of raw points to an XyDataSeries and leave resamplingMode at Auto.

Sources​