How do I increase the speed of a line plot?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (2)
Jan
am 18 Feb. 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.
0 Kommentare
Brett Shoelson
am 18 Feb. 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 Kommentare
Oleg Komarov
am 18 Feb. 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
am 18 Feb. 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
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!