Is there a way to insert a common ylabel to secondary axes in a tiled layout?

66 次查看(过去 30 天)
Hi everyone,
Dabbling a bit in MATLAB for the past year, mostly for data analysis. I am currently using version 2020 a and recently started enjoying the tiledlayout functionality. I was wondering, if there is a way to insert a shared y-axis title for secondary y-axes? For example, in this code:
t = tiledlayout(2,2);
for i = 1:4
f = figure(1);
ax = nexttile;
yyaxis left
x = (1:10);
y = rand(1,10)*100;
plot(x,y)
yyaxis right
plot(x,sin(y))
end
xlabel(t,'X')
ylabel(t,'Y')
I would like to insert a ylabel for the right axes (lets say 'Y2') that is 'shared' just as 'Y' is for the left axes. I haven't found a solution that worked for me yet, all information I could find would either relate to tiled layouts or two y axes, I haven't found something that combines the two.
I hope you understand my problem, any help is highly appreciated.

采纳的回答

Rishik Ramena
Rishik Ramena 2021-3-16
You need not create a figure for each of your tile, instead you can have a common figure which can then later be labelled as shown.
close all;
fig = figure;
t = tiledlayout(2,2);
for i = 1:4
nexttile;
yyaxis left
x = (1:10);
y = rand(1,10)*100;
plot(x,y)
yyaxis right
plot(x,sin(y))
end
ax = axes(fig);
han = gca;
han.Visible = 'off';
% X label
xlabel('X')
han.XLabel.Visible = 'on';
% Left label
yyaxis(ax, 'left');
ylabel('Y1')
han.YLabel.Visible = 'on';
% Right label
yyaxis(ax, 'right');
ylabel('Y2')
han.YLabel.Visible = 'on';

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axes Appearance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by