MATLAB Answers

App Slow With UIAxes

195 views (last 30 days)
Hi. I'm creating apps on app designer which use components such as sliders to control a plot. When plotting on a UIAxes, there is significant delay. However, when having the app plot on a separate figure, there is no delay. Does anyone know the reason for this and if there's a way to plot on the UIAxes without the delay? Thanks.
I'm going to use an app modelling a cylinder removing a lot of the additional unnecessary stuff, so the type of problem is as clear as possible. The plot consists of surf, patch, and plot3. For all apps, the goal is not plotting data per say, but rather creating shapes, often in 3 dimensions. Therefore, the data is generally arrays of type double which don't generally get over 100 elements.
I'm using MATLAB R2020a.
These are the two methods:
  • I drag and drop a UIAxes on to the app and plot on that axis. This takes about 3 seconds to update the plot each time I move the slider. This is a screenshot of the setup:
  • I create a separate regular figure (not uifigure) and plot it on that. This has almost no delay:
This is the code used to create the separate figure and have them aligned neatly (I don't think it's that important but it clarifies what I'm doing):
global ax %needed so it can be accessed through component callbacks
divide=.2;%the fraction of the screen filled by the app
fig=figure; %new figure
ax=axes(fig); %axis it will be plotted on
Here is the code which I used (I removed much of the code used in the original app to simplify things) (the code is based off of Clay M. Thompson's cylinder function, and I kept the copyright text in the code):
function torsion(ax,ax2,M,G,L,r,display_in)
% Clay M. Thompson 4-24-91, CBM 8-21-92.
% Copyright 1984-2002 The MathWorks, Inc.
% engineering equations:
% set up cylinder:
n = 50;
r = [r r]';
r = r(:); % Make sure r is a vector.
m = length(r); if m==1, r = [r;r]; m = 2; end
theta = (0:n)/n*2*pi;
sintheta = sin(theta); sintheta(n+1) = 0;
x = r * cos(theta);
y = r * sintheta;
z = (0:m-1)'/(m-1) *L* ones(1,n+1);
% plot cylinder
patch(ax,x(1,:),y(1,:),z(1,:),[.25 0 .7])
patch(ax,x(1,:),y(1,:),z(2,:),[.25 0 .7])
%plot helices
for i=0:n-1
% plot circles
for i=z_vals
J. Alex Lee
J. Alex Lee on 25 Mar 2021
thanks @Adam Danz, I think I actually confused everyone with my above posted...the way I separated was to create the figures once and for all, and then keep deleting and creating axes inside them - so the plot I showed only reflects axes creation time, and the conclusion from that should not be "ime is really spent by the uifigure call", but rather that creating uiaxes and axes alike within an existing uifigure is slower than creating them within an existing regular figure.
And the second time test I did shows that actually, plotting might be faster within uiaxes than in regular axes once they are created, whether it be within a uifigure or a regular figure. but either way, plotting is still much faster on uiaxes or axes created in a normal figure.

Sign in to comment.

Accepted Answer

Chris Portal
Chris Portal on 7 Aug 2020
Thank you @Adam Danz and @Ephraim Bryski. The additional info is useful. I see the same uifigure/uiaxes slowness Adam is showing.
Ephraim, try using a uifigure/axes combination instead. This shows similar performance results to the figure/axes combination:
  • UIFIGURE/UIAXES: Elapsed time is 1.871439 seconds.
  • UIFIGURE/AXES: Elapsed time is 0.205658 seconds.
  • FIGURE/AXES: Elapsed time is 0.204895 seconds.
A few notes:
  • UIAXES is a heavier weight version of AXES (it's effectively an axes with an invisible UI panel). This makes it slower, although the amount of slowness here is a little surprising. I'll report this to the development team to investigate.
  • The axes you get in App Designer when you drag and drop from the palette is always a UIAXES. So in order to use an AXES with your UIFIGURE, you'll need to manually create and position it as part of your startup function.
  • Lastly, these UIAXES/AXES differences will soon become a much simpler story with some up and coming work. Keep an eye out for the MATLAB release notes!
Alberto Lutman
Alberto Lutman on 2 Mar 2021
@Veronica Taurino I was not able to fix the speed issue within app designer. My work around has been having the slow part written with app-designer while plots are on a separate figure that has regular axes in it.
There are other speed-related problem even with this solution, and this is the code I use to make the axes "ASSE"
app.PGR.MenuBar='none'; app.PGR.ToolBar='none';
The additional lines help with other speed problems, like extreme slow down when mouse hoovers on the figure or hoovers over data inside the figure.
And if I can push the app designer problem of speed further, also displaying formatted tables output is problematic, the label component is fast, but it is difficult to display its string into formatted output because it has no latex interpreter. Tables would be very well formatted, and I always used them in Guide, but in app designer are so slow that are not usable to display a changing output. I ended up using annotation in the figure app.PGR, where you can set as string a latex array and set the interpreter to latex for formatted output. Just don't make a new annotation every time, but replace the string.

Sign in to comment.

More Answers (1)

Matlab User
Matlab User on 21 Mar 2021
Edited: Matlab User on 21 Mar 2021
I just installed Matlab R2021a and this is still not resolved - the jaw dropping UIAxis lag is still there. Maybe it was a mistake to fork Guide into a new thing...
@Chris Portal It seems no-one can reproduce your solution. Are you sure that you did not simply time FIGURE/AXES twice? Could you please share your code if it works for you.
I'm using some code like below (not full):
ax_id = app.UIAxes;
an = animatedline(ax_id, 'MaximumNumPoints',1000);
for i=1:1:100000
addpoints(an, x(i), y(i));
if (rem(i,100) == 0)
if i>=1000
xlim (ax_id, [i-1000+1 i]);
xlim (ax_id, [1 i]);
drawnow limitrate
Here are some timings:
  • No plotting: 60s
  • Standard Figure + axes: 63s
  • UIaxes only: 84s
I hope this will be resolved in the future - many many threads with complaints, but nothing has been done.




Community Treasure Hunt

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

Start Hunting!

Translated by