Multiple y axis on app designer

35 visualizaciones (últimos 30 días)
Carlos Quispe Galdos
Carlos Quispe Galdos el 1 de Oct. de 2022
Comentada: Eric Delgado el 3 de Oct. de 2022
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.

Respuesta aceptada

Eric Delgado
Eric Delgado el 1 de Oct. de 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 comentarios
Carlos Quispe Galdos
Carlos Quispe Galdos el 2 de Oct. de 2022
@Eric Delgado Eric I've accomplished to plot up to 4 variables on the same plot, however a new problem came across, for what I'm about to explain I reduced the variables from 4 to 3. The values on the third line (variable) don't match the values on its yaxis ruler as shown in the picture.
Below is the code with each step clearly explained from my perspective. Perhaps I'm omitting something or writing something incongruent.
Your feedback is very much appreciated.
%Data
x = (-4:.1:4)';
y = [500*cos(2*x) 10*sin(4*x) exp(x)];
%Variable
var1=y(:,1);
var2=y(:,2);
var3=y(:,3);
%Define figure handle as if it were appDesigner
figH=figure;
%Axes for variable 1 and 2 (Background and ruler VISIBLE)
hax1=axes(figH,'Position',[0.1 0.15 0.7 0.8]);
xlim(hax1,[-4 4])
pos=double(get(hax1,'Position'));
%Axes for variable 3 (Background and ruler INVISIBLE) This is
%perfectly aligned with the first axes to create the ilussion of
%overlapping 3 variables with different magnitudes on the same plot
hax2=axes(figH,'Position',pos,'color','none','YColor','none','XColor','none');
%This allows me to get the values of the lines in hax1 when I hover the mouse over
%them
set(hax2,'visible','off')
%Axes with background invisible and ruler VISIBLE for variable 3(this is
%offset to the right)
pos13=[pos(1)+0.86 pos(2) pos(3)*0.001 pos(4)];
hax13=axes(figH,'Position',pos13,'color','none','XColor','none','YColor','k','YAxisLocation','left','XGrid','off');
ylabel(hax13,'Variable 3')
%The limits from this axes will have to be defined by the min and max
%values of the variable it corresponds to, otherwise it will be incongruent
ylim(hax13,[min(var3) max(var3)])
%Variable 1 is ready to be displayed.
yyaxis(hax1,"left")
plot(hax1,x,var1)
ylabel(hax1,'Variable 1','FontSize',9)
ylim(hax1,[min(var1) max(var1)])
%Variable 2 is displayed.
yyaxis(hax1,"right")
plot(hax1,x,var2)
ylabel(hax1,'Variable 2','FontSize',9)
ylim(hax1,[min(var2) max(var2)])
%Variable 3 is displayed.
plot(hax2,x,var3,'k')
set(hax2,'visible','off')
Eric Delgado
Eric Delgado el 3 de Oct. de 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')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by