Setting two yaxes in uifigure

4 Ansichten (letzte 30 Tage)
Dominik Frymark
Dominik Frymark am 5 Sep. 2023
Kommentiert: Dominik Frymark am 5 Sep. 2023
I would like to use two yaxes in my figure. But in the uifigure environment I fail to do so. How do I set the left yaxis with 'label 1' and the right yaxis label with 'label 2'? Attached is my code and a screenshot:
soc = out_rulebased.SoC.signals.values
time = linspace(0,10,length(ibatref_rulebased))
i_load = out_rulebased.i_load.signals.values
f = uifigure;
ax = axes(f);
plot(ax, time, i_load/10, time, soc,LineWidth=3)
legend(ax, 'Load current','SoC','fontsize',30)
xlabel(ax,'Time [d]', 'FontName', 'Latin Modern Roman', 'FontSize', 55);
ylabel(ax,'Current [A/10], SoC [%]', 'FontName', 'Latin Modern Roman', 'FontSize', 55);
set(ax, 'FontName', 'Latin Modern Roman', 'FontSize', 45);
  2 Kommentare
Guillaume
Guillaume am 5 Sep. 2023
plot(time, i_load/10, LineWidth=3);
ylabel('Current [A/10], SoC [%]', 'FontName', 'Latin Modern Roman', 'FontSize', 55);
yyaxis right % < tell to plot on a new ax on the right
plot(time, soc, LineWidth=3);
ylabel("Right y axis label", 'FontName', 'Latin Modern Roman', 'FontSize', 55);
xlabel(ax,'Time [d]', 'FontName', 'Latin Modern Roman', 'FontSize', 55);
This should do the trick but I can't test right now.
Dominik Frymark
Dominik Frymark am 5 Sep. 2023
Thanks this adds the two yaxes, but I would like to stay in the uifigure environment, since here I can do the scaling and export of the figure like I have done with all my figures before. Also the font changes then.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 5 Sep. 2023
Try this
soc = out_rulebased.SoC.signals.values
time = linspace(0,10,length(ibatref_rulebased))
i_load = out_rulebased.i_load.signals.values
f = uifigure;
ax = axes(f);
yyaxis(ax,'left') % ADDED
plot(ax, time, i_load/10, LineWidth=3) % CHANGED
ylabel(ax,'Current [A/10], SoC [%]', 'FontName', 'Latin Modern Roman', 'FontSize', 55); % MOVED
yyaxis(ax,'right') % ADDED
plot(ax, time, soc, LineWidth=3) % ADDED
ylabel(ax,'________________', 'FontName', 'Latin Modern Roman', 'FontSize', 55); % ADDED
legend(ax, 'Load current','SoC','fontsize',30)
xlabel(ax,'Time [d]', 'FontName', 'Latin Modern Roman', 'FontSize', 55);
set(ax, 'FontName', 'Latin Modern Roman', 'FontSize', 45);

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by