Setting two yaxes in uifigure
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Guillaume
2023 年 9 月 5 日
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.
採用された回答
Adam Danz
2023 年 9 月 5 日
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);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!