Enhance zooming and panning on large data sets by automatically downsampling data


Updated 21 Jan 2009

View License

Function for plotting large data sets (e.g. time-series with more than 1e6 data points).
The main benefit of this function can be seen in the fact that zooming and paning will work much smoother,
since the data is automatically downsampled to 1e4 points (=> change "n_points" for different number).

The usage is exactly identical to the regular plot-command, i.e.:



Will only work in Matlab 7.3 or higher.

"DeleteFcn" & "CreateFcn" are used for plotted line and should not be overwritten.
The "ActionPostCallback" (=> zoom & pan) is also used and cannot be used otherwise in the according plots / figures.

Downsampling is simply performed by plotting only every n-th data point. Therefore, aliasing may occur !!!

Data is clipped outside current axislimits and is updated to the current axis-limits after panning / zooming is finished.

Using double-clicking in "zoom-in" modus might not work as expected, because the dispayed data-set
is clipped. It is possible to return to the original data-set by using the scroll-wheel or the "zoom-out" tool.

The x- & y-data is stored as application-data to the plot-handle.

To get the true x- and y-data for the line with handle h, use ...
x = getappdata(h,'LDS_xdata');
y = getappdata(h,'LDS_ydata');

EXAMPLES (Use zoom & pan; compare to regular plot-command !!!

phi = linspace(0,2*pi,1e6); plotLDS(sin(x),cos(x),'.')

ax(1) = subplot(2,1,1); plotLDS(rand(1e6,1))
ax(2) = subplot(2,1,2); plotLDS(rand(1e6,1))

plotLDS(rand(1e6,1)); ax(1)=gca; figure; plotLDS(rand(1e6,1)); linkaxes(ax,'x'); ax(2)=gca; linkaxes(ax,'x')

Jiro Doke informed me that his submission "DSPLOT", which was chosen as "Pick of the Week", performs a similar task as this submission. I did not notice before and of course he should be acknowledged.

I did a quick comparison on the two submissions and noticed the following differences:
1) plotLDS is not restriced to single figures / axes but will work for arbitrary combinations. Most important: it will also work for linked axes !!!
2) plotLDS is not restricted to plots with monotonically increasing x-data, but will also handle plots with monotonically increasing y-data and plots with unstructured data (e.g. point-clouds).
3) plotLDS uses exactly the same syntax as the regular "plot"-command. This facilitates the use of this command by simply replacing "plot" by "plotLDS" without having to care for input-arguments.
3) Jiro's submission (DSPLOT) includes a more advanced way of investigating the data to make sure it doesn't miss any "outliers".

Cite As

Sebastian Hölz (2023). plotLDS (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Revision 33:
- plotLDS now relies on "CallbackStack", which is supplied together with this file.
- New switches.
- Input style for switches changed slightly.
- Bug-fixes.

Fixed several bugs.
It is now possible to directly link plotted data to the base workspace: plotLDS(y,'ydatasource','y'). This greatly reduces the memory need.