Clear Filters
Clear Filters

Issue with slanted y-axis ticks when using UIAxes component in app designer.

6 views (last 30 days)
Hi,
I'm attempting to create a MATLAB app that displays a 2D plot but I'm intermittently having issues with the Y-axis tick when inserting a UIAxes plot.
It only seems to happen for certain combinations of x and y data. My guess is it has something to do with how the UIAxes supports all 3 axis. For some reason there isn't an option to lock the UIAxes into a 2d format what I can tell.
I've tried programmatically resetting the viewing angle after plotting but that doesn't seem to fix it.
Here is the code I'm using to plot:
plot(Ax,X,Y,'-k');
view(Ax, 0, 90);
grid(Ax,'minor');
Any help would be much appreciated.

Accepted Answer

Simar
Simar on 14 May 2024
Edited: Simar on 15 May 2024
Hi John,
As per my understanding you are trying to maintain 2D perspective for plot in MATLAB App (using UIAxes), but there are challenges with the Y-axis ticks under specific conditions The command view(Ax, 0, 90); aims to present the plot in 2D by adjusting the viewing angle, which is an appropriate method. If problem persists following solutions can help in troubleshooting and potentially solving the issue:
1. Ensure Correct Viewing Angle: Use of view(Ax, 0, 90) is correct for setting 2D view. However, make sure this command is executed after the plot is rendered. This is because some plotting commands may reset the camera view, potentially overriding the specified view settings.
2. Axis Limits and Ticks: If issue is specifically with Y-axis ticks, consider setting Y-axis limits and ticks explicitly to ensure they are displayed as expected. For example:
ylim(Ax, [minY maxY]); % Set Y-axis limits
yticks(Ax, linspace(minY, maxY, numTicks)); % Set Y-axis ticks
Adjust minY, maxY, and numTicks as needed for your data.
3. Force Redraw: Forcing the UI to redraw can help. After setting your view, you might want to use drawnow; to ensure UI updates with specified settings.
4. Debugging: Try isolating the issue that only includes the UIAxes and the plotting functionality. This can help determine if the issue is with data, the plotting commands, or interference from other parts of the app.
Here is a refined snippet incorporating some of the suggestions:
plot(Ax, X, Y, '-k');
grid(Ax, 'minor');
ylim(Ax, [min(Y) max(Y)]); % Assuming Y is your data vector
yticks(Ax, linspace(min(Y), max(Y), 10)); % Example: 10 ticks across the Y range
view(Ax, 0, 90); % Ensure this is after plotting commands
drawnow; % Force the UI to update
If problem is specific (only occurs with certain data sets or under specific conditions), it might be helpful to examine the data or conditions under which issue arises more closely. Check combinations of X and Y data that triggers this behaviour, such as large or small values, NaNs that could be affecting default axis limits and ticks.
Please refer to the following documentation links-
Hope it helps!
Best Regards,
Simar
  1 Comment
John
John on 15 May 2024
Those all seem like reasonable tips. I haven't tried all of them but one of them might work.
What I have figured out since posting is that constraining the zlim range to something really small also resolves the issue.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!