MATLAB Answers


App Designer Axis Issue

Asked by Raees Mohammed on 24 Feb 2018
Latest activity Edited by Sami Kanderian on 11 Nov 2018
Hi, I'm creating an app in App Designer that allows a user to select different button configurations and then click a pushbutton to load a plot on an app.UIAxes. The problem is after you run the app a couple of times (the exact number I'm not sure), the properties of the app.UIAxes change such that it jumbles my plot together to the upper right corner of the axis. The way I fix this is by deleting the axis in the editor and replacing it with another. Then it runs and displays the plot on the axis as it should. This is what the axis looks like in the code that I cannot change for App Designer:
% Create UIAxes
app.UIAxes = uiaxes(app.LayerMappingUIFigure);
app.UIAxes.Position = [1 9 634 500];
When the axis displays the image in a jumbled, undesired way, the App Designer code I cannot change looks like this:
% Create UIAxes
app.UIAxes = uiaxes(app.LayerMappingUIFigure);
app.UIAxes.DataAspectRatio = [1 1 1];
app.UIAxes.PlotBoxAspectRatio = [1 1 1];
app.UIAxes.XLim = [0 1];
app.UIAxes.YLim = [0 1];
app.UIAxes.ZLim = [0 1];
app.UIAxes.CLim = [0 1];
app.UIAxes.GridColor = [0.15 0.15 0.15];
app.UIAxes.MinorGridColor = [0.1 0.1 0.1];
app.UIAxes.XColor = [0.15 0.15 0.15];
app.UIAxes.XTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
app.UIAxes.YColor = [0.15 0.15 0.15];
app.UIAxes.YTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
app.UIAxes.ZColor = [0.15 0.15 0.15];
app.UIAxes.ZTick = [0 0.5 1];
app.UIAxes.CameraPosition = [0.5 0.5 9.16025403784439];
app.UIAxes.CameraTarget = [0.5 0.5 0.5];
app.UIAxes.CameraUpVector = [0 1 0];
app.UIAxes.Position = [1 1 634 510];
I'm relatively new to App Designer, or app development in general. Can someone help me resolve this issue?


Some clarifying questions:
  • What version of MATLAB are you using?
  • When designing your app, are you changing any UIAxes properties using the property list on the right-side of the App Designer window?
  • Is there any chance you can upload your app as an attachment?
I would like to mention that I also experienced this. I have a fairly large app (approximately 10 uiaxes) and, seemingly randomly, many of the properties of all of the uiaxes were suddenly changed to 'manual'. I had not been modifying any of the properties in the App Designer or within the code. I ended up replacing all of the uiaxes rather than manually toggling everything back to 'auto'. I am using Matlab R2017b.

Sign in to comment.

3 Answers

Answer by Benjamin Kraus on 5 Mar 2018

Based on the block of code that you say you cannot modify, it looks like App Designer thinks you have manually specified all those values. Once you have manually told App Designer to use a specific value for a property, App Designer will stop automatically calculating the value for you.
In this case, it looks like XLim and YLim (and many other properties) have been manually specified to be [0 1], which means that even if you plot data spanning from 10-100, MATLAB will try to honor your request to keep the limits at [0 1], and you won't see any of your data.
This could happen if you were browsing through the list of properties and click on each one individually, and App Designer (perhaps by mistake) interpreted that as as an intent to set a value. When you set a value, the corresponding mode value toggles to from 'auto' to 'manual'. To fix it, you can toggle the mode back to to 'auto'.
For example, looking at the list, App Designer thinks that you have manually set the values for XLim, YLim and ZLim. To tell App Designer to automatically calculate those values, you need to make sure that XLimMode, YLimMode, and ZLimMode are all set to 'auto'. You can do that for the Mode property corresponding to each of the properties in the list above.
Alternatively, you can delete the UIAxes and create a new one with new default settings. You can save yourself a little time by copying the Position before you delete the old UIAxes, create a new UIAxes, then paste the old value of Position to put your new UIAxes back into the same location as the old one.
Finally, it is worth pointing out a difference between how UIAxes and Axes behave when plotting:
  • Regular Axes will automatically reset all the properties (including XLim, YLim, etc.) when you call commands like plot.
  • UIAxes will typically not automatically reset any properties when you call plot. This means that any properties you have manually specified when designing your app will be preserved after a call to plot.
This difference in behavior is based around the value of the NextPlot property. On regular Axes the default value of NextPlot is 'replace'. On UIAxes the default value is 'replacechildren'.
You can read about the NextPlot property on the documentation page for the newplot command. Commands like plot call newplot internally.
If you want UIAxes to behave more like regular Axes, you can manually set the NextPlot property to 'replace' before you plot:
app.UIAxes.NextPlot = 'replace';
plot(app.UIAxes, 1:10)
or you can manually reset the axes using the cla command:
plot(app.UIAxes, 1:10)

  1 Comment

I have the same problem and am using R2017b. I fixed it multiple times: I removed the axis and put a new one, but it happened repeatedly. It's so frustrating much so that I gave up on App designer and am switching to Java. Sure it takes longer to code algorithms in Java, but at least the UI behaves predictably and does not change unless I tell it to.

Sign in to comment.

Answer by Raghu S
on 26 Jul 2018

This command solved my same issue. Just place this code in StartFCn cla(app.UIAxes,'reset')


Sign in to comment.

Initially, the required data was not visible in my app.UIAxes.
I did the following steps:
1. app.UIAxes = uiaxes(app.LayerMappingUIFigure); % Blank axes appeared in my GUI
2. app.UIAxes.Position = [1 9 634 500]; % To move to the required position in the GUI
3. app.xdata, app,ydata % app.UIAxes x-axis and y-axis scaling
4. app.UIAxes.XLim app.UIAxes.XLabel.String app.UIAxes.YLim app.UIAxes.YLabel.String
5. plot(app.UIAxes,app.xdata,app.ydata) % to plot the required _data


Sign in to comment.