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
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.
0 件のコメント
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
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
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 Center および File Exchange で Graphics Performance についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!