Setting two yaxes in uifigure
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dominik Frymark
le 5 Sep 2023
Commenté : Dominik Frymark
le 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 commentaires
Guillaume
le 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.
Réponse acceptée
Adam Danz
le 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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!