Setting two yaxes in uifigure

3 ビュー (過去 30 日間)
Dominik Frymark
Dominik Frymark 2023 年 9 月 5 日
コメント済み: Dominik Frymark 2023 年 9 月 5 日
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
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.
Dominik Frymark
Dominik Frymark 2023 年 9 月 5 日
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.

サインインしてコメントする。

採用された回答

Adam Danz
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);
  1 件のコメント
Dominik Frymark
Dominik Frymark 2023 年 9 月 5 日
Works great, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by