Setting two yaxes in uifigure
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dominik Frymark
el 5 de Sept. de 2023
Comentada: Dominik Frymark
el 5 de Sept. de 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 comentarios
Guillaume
el 5 de Sept. de 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.
Respuesta aceptada
Adam Danz
el 5 de Sept. de 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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects 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!