Is there a way to insert a common ylabel to secondary axes in a tiled layout?
67 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Manuel Bruch
il 13 Mar 2021
Commentato: Shahrose Khan
il 1 Giu 2021
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.
0 Commenti
Risposta accettata
Rishik Ramena
il 16 Mar 2021
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';
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Axes Appearance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!