How do I increase the speed of a line plot?

5 次查看(过去 30 天)
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.

回答(2 个)

Jan
Jan 2011-2-18
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 2011-2-18
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 个评论
Oleg Komarov
Oleg Komarov 2011-2-18
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 2011-2-18
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by