Best Performance to: plot 300-400e6 lines and saving this figure handle

3 次查看(过去 30 天)
Hi Matt, all... I would once again like to see if this can be plotted using surface or something else.
I have some example code attached with necessary mat file, thanks.
(crossings_mat.mat and example_lineplot.m)
------------- Original Post
I have been searching the past few days to improve a plot im generating and saving using export_fig.
the plot + save time is ~480s. Saving doesnt seem to take more than ~100-150s.
Still, i was hoping to more easily be able to explore the plot rather than simply examining the saved png/jpg. I downloaded and tried to use the LinePlotReducer but was not successful. additionally, since prior to this experience i was not very familiar with figure handles i have seen examples for set(gca,'YData',dataY). Still, i am not incredibly confident with them and their plotting performance over "plot."
I have also read suggestions from using "line" over plot, using "set" on the plot handles "Children" property with YData but these latter suggestions im not as clear on and had trouble doing this.
PS. Do i need to see all the data? I believe my response is yes, i do. That is b/c im looking for the unknown relationship between the two waveform's this plot creates as its overlapping segments from the index vector+/-offset where each "line" is the 4001 points. I could potentially plot every other point within the segment, but that would be the only improvement... im wondering if there is a more fundamental method to plot for performance given this case.
i tried to use the "set" command by setting h2 = plot(Nan,Nan); but this wont "hold" % set(h2,'YData',waveform1(:,k),'Color',[0 0 1]); % set(h2,'YData',waveform2(:,k),'Color',[0 1 0]);
if anyone has suggestions for fastest "fundamental" way to plot multiple lines/functions on the same plot, please share. thanks
Sample Code: *note1 that, the two waveforms have same length N (same Fs). *note2 length(indexs) ~= 75-100k and is the waveform2 indexs at specific locations
Original Method: simply step through the waveforms and plot each segment loopbyloop. tic/toc = 316s (~5min) w/export_fig disabled (4s faster than 2nd method)
h1 = figure('doublebuffer','on');
set(h1,'Units','pixels','Position',[5 5 700 500]);
hold all;
fig = gca;
set(fig,'drawmode','fast');
set(fig,'xlim',[0 2*offset]);
set(fig,'ylim',[(min(waveform1)-0.25) (max(waveform1)+0.25)])
set(fig,'Xticklabel',{'0.0','','0.25','','0.5','','0.75','','1.0'});
hold all;
for inc=3:length(indexs)-3
temp_left_index = indexs(inc)-offset;
temp_right_index = indexs(inc)+offset;
%just need to plot against the index
plot(waveform1(temp_left_index:temp_right_index),'b');
plot(waveform2(temp_left_index:temp_right_index),'g');
end
export_fig(h1,file_to_write,'-a2','-nocrop','-q75','-jpg'); toc;
2nd Method: create a matrix of the segments for each waveform first... access and plot this matrix col-wise contiguously for speed? tic/toc = 480s (8min!) w/export_fig enabled tic/toc = 320s (>5min) w/export_fig disabled
h1 = figure('doublebuffer','on');
set(h1,'Units','pixels','Position',[5 5 700 500]);
hold all;
fig = gca;
set(fig,'drawmode','fast');
set(fig,'xlim',[0 2*offset]);
set(fig,'ylim',[(min(waveform1)-0.25) (max(waveform1)+0.25)])
set(fig,'Xticklabel',{'0.0','','0.25','','0.5','','0.75','','1.0'});
hold all;
wv1_segs = zeros(2*offset+1,length(indexs)-3);
wv2_segs = zeros(2*offset+1,length(indexs)-3);
for inc=3:length(indexs)-3
temp_left_index = indexs(inc)-offset;
temp_right_index = indexs(inc)+offset;
% storing contiguously col-based since i need to plot along the 2*offset length
wv1_segs(:,inc-2) = waveform1(temp_left_index:temp_right_index);
wv2_segs(:,inc-2) = waveform2(temp_left_index:temp_right_index);
end
for k = 1:(length(REF_indexs)-3)
plot(wv1_segs(:,k),'b');
plot(wv2_segs(:,k),'g');
%refreshs the plot every 1/10*index length
if rem(k/round((length(indexs)-3)/10),1) == 0
drawnow;
end
end
export_fig(h1,file_to_write,'-a2','-nocrop','-q75','-jpg'); toc;
  3 个评论
cmmv
cmmv 2014-12-8
编辑:cmmv 2014-12-8
i updated to plot only every 40th point... so 4000/40--> 100 points for horizontal resolution. the tic/tock is definitely less, but as to my fundamental question: Is there a "fastest" method to plotting lots of lines? (100points*75e3:100e3 lines)
tic/toc without save is now 140s. so 2.25x speedup but, i would still love for this to be only ~20-30s max.

请先登录,再进行评论。

回答(1 个)

matt dash
matt dash 2014-12-6
编辑:matt dash 2014-12-6
It's not entirely clear what you're trying to accomplish. Are you comparing 300 million waveforms, or 2 waveforms that each contain 300 million data points?
Looking at your code, it's not clear why you aren't just doing: plot(waveform1,'b') plot(waveform2,'g')
Maybe there is a good reason, but it's not readily apparent. Maybe clarify your question.
If you really do need to plot 300million different line segments, if each one contains the same number of samples you can use a single call of the "surface" function with the 'meshstyle','row' option to plot all the lines at once. this is generally much faster than creating a bunch of individual line objects... the only thing you lose is the ability to independently color each line, but it looks like you don't need that anyway. (You can however still assign a unique color to each line as long as they map to a colormap)
Example: For me this takes 1 second for the surface and about 100 seconds for the lines:
close all
x=rand(1000000,10);
y=rand(1000000,10);
tic
figure
axes
surface(x,y,zeros(size(x)),'meshstyle','row','facecolor','none')
drawnow;
toc
tic
figure
axes
for i = 1:size(x,1)
line(x(i,:),y(i,:))
end
drawnow;
toc

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by