Efficient Plots with StackedPlot

6 次查看(过去 30 天)
Hi all,
I am attempting to create a stackedPlot, I specifically want to use this to have the ability to scroll through my data with a marker over my cursor and to have multiple pieces of data with the same x axis. I have some fairly large datasets and I am running into performance issues. After some testing, I think most of this can be attributed to how I am combining y axes, adding labels etc. I have included code snippets below, any advice is appreciated.
I already plan on removing points from the data set and then making full resolution plots only in the range where it is required.
Thanks,
Ben
I ran these tests with a reduced data set of 14,000 elements:
tic;
figure(1);
engineData = [time eSpeed eSetPoint ePID_P ePID_I ePID_D ePID eState speed_mph fBRK, rBRK];
engineData = array2table(engineData);
engineLoopFastPlot = stackedplot(engineData);
toc
The ellapsed time for the above is .05 sec
tic;
engineLoopFig = figure('Name', 'Engine Loop Data', 'NumberTitle', 'off');
engineData = array2table([time eSpeed eSetPoint ePID_P ePID_I ePID_D ePID eState speed_mph fBRK, rBRK]);
engineData = renamevars(engineData, ["Var1" "Var2" "Var3" "Var4" "Var5" "Var6" "Var7" "Var8" "Var9" "Var10" "Var11"],...
["Time" "Engine Speed" "Engine Speed Setpoint" "Engine P" "Engine I" "Engine D" "Engine PID" "Engine State" "Car Speed" "Front Brake" "Rear Brake"]);
engineVars = {'Engine State',{'Engine Speed', 'Engine Speed Setpoint'},...
{'Engine P', 'Engine I','Engine D','Engine PID'},...
{'Car Speed'},...
{'Front Brake', 'Rear Brake'}};
engineLoopTL = stackedplot(engineData, engineVars, 'XVariable','Time');
engineLoopTL.AxesProperties(2).YLimits = [1600 4200];
engineLoopTL.AxesProperties(4).YLimits = [0 60];
toc
The ellapsed time for the above is 1.00 sec
  3 个评论
dpb
dpb 2023-4-15
Well, I just made up some dummy data and tried it...
N=10000;
tic;tS=array2table([[0:(N-1)].',rand(N,9)],'VariableNames',{'Time','eSpeed','eSetPoint','ePID','ePID_I','ePID_D','eState','mph','fBrake','rBrake'});toc
Elapsed time is 0.025932 seconds.
engineVars = {'eState',{'eSpeed', 'eSetPoint'},...
{'ePID', 'ePID_I','ePID_D'},...
{'mph'},...
{'fBrake', 'rBrake'}};
tic;figure,stackedplot(tS,'XVariable','Time');toc
Elapsed time is 2.832633 seconds.
tic;figure,stackedplot(tS,engineVars,'XVariable','Time'),toc
Elapsed time is 0.868260 seconds.
Which is quite a lot faster for the grouped plots than it is for the ugrouped. Of course, there are only five of those instead of 10 for each variable which would seem to make some sense that it has the axes overhead for half as many.
Let's compare to see...
tic;stackedplot(tS,'XVariable','Time');toc
Elapsed time is 4.957262 seconds.
tic;stackedplot(tS(:,1:5),'XVariable','Time');toc
Elapsed time is 2.000997 seconds.
and, indeed, it's about 40% the time for 44% the number axes created...
Viktor Janzen
Viktor Janzen 2023-4-27
I made the experience, that the problem is not the stackedplot himself, but all manipulations of the stackedplot after creating it.
Have you run the profiler through your code? I guess that the 2 lines
engineLoopTL.AxesProperties(2).YLimits = [1600 4200];
engineLoopTL.AxesProperties(4).YLimits = [0 60];
will take more time than you think. I have a similar problem, see below.
The manipluation after creating the stackedplot are necessary to make the whole plot more comfortable
What is needed, to stop applying new manipulations commands between, but to apply all manipulations in one time, like it is with normal plot-commands (-> drawnow). In earlier releases (like R2021a) this was not a problem.
Is there any workauround from MathWorks for that?

请先登录,再进行评论。

回答(0 个)

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by