View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 8.23 KB File ID: #18857 Version: 1.1




20 Feb 2008 (Updated )

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

| Watch this File

File Information

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".

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
05 Apr 2013 Erik Benkler

Erik Benkler (view profile)

Hi Sebastian,

thanks for this very useful contribution. You say it is completely compatible with the plot Syntax. However, I receive an error message if I use it with the 'XScale' and related properties:
It would be nice if you could implement similar downsampling for logarithmic axes, with equidistant data points on the log scale. In this case, you will probably have to interpolate. E.g., plotLDS(log10(x),y) produces poor results since too many of the small x values are left out with respect to those at large x.

17 Jan 2012 Sebastian Hölz

Hello Hoi,

as the documentation says ... : "The usage is identical to the regular plot-command for VECTORS ...". So, if you have matrices, you will just have to break them apart and plot each column separately.



Comment only
16 Dec 2011 Hoi Wong

Hoi Wong (view profile)

my data has multiple columns (in a matrix), which the regular plot() command or Jiro's dsplot() will draw multiple lines correctly. plotLDS() gave me this error message:

Error in ==> plotLDS at 177
h = plot([min(x) min(x) max(x) max(x)],[min(y) max(y) min(y) max(y)], ...

I'd like to use this feature in subplots, but it seems like Jiro's version doesn't support it.

Comment only
20 Feb 2008 Jiro Doke

Hi Sebastian,
Just wanted to let you know I also created a similar function:

Comment only
22 Feb 2008

V1.1 (22.02.08): Works for all plotting-syntaxes, monotonically increasing y-data, unstructured data, and for saving and reloading a figure.

V1.0 (20.02.2008): First release

21 Jan 2009 1.1

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

Contact us