Code covered by the BSD License

### Highlights from Plot (Big)

4.54545

4.5 | 11 ratings Rate this file 66 Downloads (last 30 days) File Size: 13.3 KB File ID: #40790

# Plot (Big)

15 Mar 2013 (Updated )

Makes MATLAB's line plots much faster.

### Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

File Information
Description

This simple tool intercepts data going into a plot and reduces it to the smallest possible set that looks identical given the number of pixels available on the screen. It then updates the data as a user zooms or pans. This is useful when a user must plot a very large amount of data and explore it visually.

This works with MATLAB's built-in line plot functions, allowing the functionality of those to be preserved.

plot(t, x);

One could use:

reduce_plot(t, x);

Most plot options, such as multiple series and line properties, can be passed in too, such that 'reduce_plot' is largely a drop-in replacement for 'plot'.

h = reduce_plot(t, x(1, :), 'b:', t, x(2, :), t, x(3, :), 'r--*');

This function works on plots where the "x" data is always increasing, which is the most common, such as for time series.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
08 Feb 2014

Hi Tucker McClure

yes, now it's working :)

sorry for the silly question and thanks for the clear answer!

06 Feb 2014

Hi veleno85,

Ah, yes, you can't pass cell arrays directly to 'plot'. Notice that your commented-out line 'plot(Load{...})' uses curly brackets and so is actually returning a matrix and not a cell array. However, you're passing the cell arrays to reduce_plot. There are many ways to fix this.

% Easiest way
Time = cell2mat(Data(:, 1));

% Use curly braces to access the cells and add square brackets to form a new matrix with the guts of all those cells (a little harder to understand).
Time = [Data{:, 1}];

Alternately, if your 'importfile' function is auto-generated using the Import Tool, then you could re-run the Import Tool and select "column vectors" as the output type so that you don't have to select columns from a big cell array. Then you could generate a new 'importfile' function with this option.

Does that help?

And welcome to MATLAB. :)

06 Feb 2014

Hi, i'm pretty new in MATLAB and i'm trying to print my huge amount of data. using reduce_plot in this code i get this error, i'm sure i'm making some basic mistake.. do u have any idea?
Data are in a cell array

close all; clear all; clc;

Data = importfile('25112013.xls','Ark1','A6:P35785');

Time = Data(:,1);

T= Time';

reduce_plot(L,T)

LinePlotReducer had trouble managing the plot function. Perhaps the arguments are incorrect. The error is below.
Error using plot
Not enough input arguments.

Error in LinePlotReducer (line 402)
o.h_plot = plot_fcn(plot_args{:});

Error in reduce_plot (line 12)
lpr = LinePlotReducer(varargin{:});

reduce_plot(L,T)

15 Jan 2014

Updated to work with input data in different combinations of rows and columns, more like MATLAB's built-in functions (see "Updates" below).

Thanks, Edwin and Greg. These should both be fixed.

15 Jan 2014

Very nice and very usefull! Maybe a small issue: the data should be in a colomn vector; you get no warning when the data is in a row vector and Matlab stops functioning.

07 Jan 2014

Nice work as always.

11 Nov 2013

Great program!

But here's the issue: It seems to work for a stand alone axis.

But it does not work if I'm trying to hand over an axis in a GUI to it (I don't know if I'm doing it right though).

For example, I have a GUI with 5 separate axes and I need to specify which one I want to plot my data to.

So I have:

h=plot(handles.RawData,data); %handles.RawData is the reference to the axis
LinePlotReducer(h);

But I get the error:

Cell contents reference from a non-cell array object.

Error in LinePlotReducer (line 157)
o.x{k} = o.x{k}(:);

Seems though that what's causing the problem here is the section in LinePlotReducer that deals with this which seems to think that the 'XData' field in the handle for plot is a cell array when in fact it is just a regular array.

Or maybe I'm not doing something right

29 Oct 2013

Excellent!

24 Jun 2013

Excellent point, dberm22.

Kelly, good suggestions. Plotting detailed coastlines would be a great use case for improvement! In the meantime, if you're displaying landmasses with patches, do you know about reducepatch? This could be used (pre-rendering) for multiple levels of fidelity.

Thanks to all for the ratings!

24 Jun 2013

I did my own testing on this for speed, and at first I was tempted to give this 1 star because the tic-toc results show that reduce_plot() takes twice as long to create the plot than the regular plot() does. Don't be fooled by this! tic-toc does not take into account how long it takes to show the plot on the screen, for which reduce_plot() is extremely efficient. Also, with the such large amount of numbers I was using, zooming was rendered impossible with the normal plot() function. reduce_plot() was a life-saver in those scenarios.

plot() = 1.66s (create plot) + 7.54s (show on screen) = 9s total (& cannot zoom)
reduce_plot = 3.65s (create plot) + .8s (show on screen) = 4.45s total + .7s (zooming) = priceless

18 Jun 2013

Very useful function. However, it currently only works if your data describes a function (in the mathematical sense of one y per x). It would be great if it could be extended to work when the y axis is the independent variable, or for lines defining polygons (for example, I originally stumbled on this looking for a more efficient way to plot high-resolution coastlines while allowing lots of efficient zooming and panning).

12 Jun 2013
07 Jun 2013

Awesome!

10 Apr 2013
03 Apr 2013
25 Mar 2013
06 Jan 2014

Fixed a bug when "taking over" a plot with only a single line. Fixed a bug that caused the final line spec in a series to be ignored.

15 Jan 2014

Now allows inputs as combination of rows and columns, like the built-in plot functions. For instance, these all do the same thing:

x = 1:10;
y = [1:10; 2:11];
reduce_plot(x, y);
reduce_plot(x.', y);
reduce_plot(x, y.');
reduce_plot(x.', y.');