How do I increase the speed of a line plot?

1 vue (au cours des 30 derniers jours)
Daniel barth
Daniel barth le 18 Fév 2011
If I plot 256 line objects (3000 points each) on the screen using plot, it takes about 0.1 sec the first time. After that successive plots take far longer 1-2 sec.
I have included all the tricks I can find
  • Setting EraseMode to 'none' or 'xor'
  • Only updating Ydata instead of replotting the objects
  • Setting X and Y limits to manual
  • etc...
Yet by far always the fastest plot is if I clear the axes (CLA) and just plot the lines again. Surely just updating the Ydata or just changing the color of the existing line objects should be far faster than replotting from scratch on cleared axes.
  1 commentaire
Oleg Komarov
Oleg Komarov le 18 Fév 2011
Post some code so we can try out.

Connectez-vous pour commenter.

Réponses (2)

Jan
Jan le 18 Fév 2011
You can set the XLim, XTicks, XTickMarks (same for Y) to 'manually', if this is possible for your problem. Then Matlab does not have to check and recalculate the limits and ticks.
There is an undocumented property "YLimInclude" and "XLimInclude" also, which disables the checks if it is set to 'off'.
The used renderer affects the speed also. While LINE plots with the '-' style are fast in OpenGL, the line style '.' is much slower.

Brett Shoelson
Brett Shoelson le 18 Fév 2011
Daniel,
Withoug seeing your code, it's difficult to guess what's causing the slowdonw. But try using LINE instead of PLOT. I just created 256 lines, 3000 points each, in about 0.1 seconds:
x = linspace(0,5,3000);
n = 256;
y = zeros(n,numel(x));
for ii = 1:n
y(ii,:) = x.^(1+ii/numel(x));
end
colors = jet(n);
figure
tic
for ii = 1:n
line(x,y(ii,:),'color',colors(ii,:));
end
toc
Cheers,
Brett
  2 commentaires
Oleg Komarov
Oleg Komarov le 18 Fév 2011
The OP :" If I plot 256 line objects (3000 points each) on the screen using plot, it takes about 0.1 sec the first time. After that successive plots take far longer 1-2 sec."
So, it's about what happens after.
Brett Shoelson
Brett Shoelson le 18 Fév 2011
Okay, so I wrapped that loop in an outer one, and timed each call to my loop of 256 lines. (I captured the timings in variable JTIMES.) I also shifted the x position of the lines with each outer call. The results:
>> mean(jtimes)
ans =
0.1209
>> std(jtimes)
ans =
0.0047
Am I missing something?
Brett

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by