Multiple y axis on app designer

8 views (last 30 days)
Hello guys, I've come across a problem developing an app. I'm analyzing a fleet performance and I need to plot up to 4 variables on the same plot.
I've managed to get the plot on the live editor following other posts, my result is as shown.
However, when I replicate the same on the app designer I just get one variable on the plot (not using yyaxis for at least 2 variables). I'm using the technique of creating invisible axes.
Trying to solve this problem I've realized the following:
  • If I make a simple code using the transparent axes method on the live editor I get the following, similar to the previous plot which is what I'm looking for.
  • If I copy the same code on the app designer I get the same with my original problem, the line that is supposed to be on the invisible axes doesn't appear on the plot.
  • If I change the parent of the axes to figure not UIFigure I do get what I'm looking for but on another window.
I've hit the wall here, the due date for this project is coming soon and I have no idea how to solve this. Perhaps it is not possible to plot 4 variables with different magnitudes on the same plot using the appdesigner (like 1800 for RPM, another variable could be 15 Amps for the electric motor, 2300 psi for pressure, 1 or 0 for logical states, etc.)
Any idea is very well welcomed.
Thank you.

Accepted Answer

Eric Delgado
Eric Delgado on 1 Oct 2022
I think you can create an invisble figure (the old one) and use copyobj to copy the lines for your uiaxes. Or you can create your axes programmatically using uigrid (or other approach) to hold them "together". See app attached (made in R2021b).
.
  3 Comments
Eric Delgado
Eric Delgado on 3 Oct 2022
Three plots in just one "axes"?! You are a brave man! :)
So... your problem was your third axes. See code below.
x = (-4:.1:4)';
y = [500*cos(2*x) 10*sin(4*x) exp(x)];
fig = figure;
ax1 = axes(fig, 'Position', [0.1 0.15 0.7 0.8]);
ax2 = axes(fig, 'Position', ax1.Position, 'Color', 'none', 'YAxisLocation', 'right');
hold(ax1, 'on')
hold(ax2, 'on')
yyaxis(ax1, 'left')
plot(ax1, x, y(:,1))
ylabel(ax1, 'Variable 1')
yyaxis(ax1, 'right')
plot(ax1, x, y(:,2))
ylabel(ax1, 'Variable 2')
plot(ax2, x, y(:,3))
ylabel(ax2, 'Variable 3')
ytickformat(ax2, ' %.0f')
linkaxes([ax1, ax2], 'x')

Sign in to comment.

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by