Is there a way to insert a common ylabel to secondary axes in a tiled layout?
55 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Manuel Bruch
el 13 de Mzo. de 2021
Comentada: Shahrose Khan
el 1 de Jun. de 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 comentarios
Respuesta aceptada
Rishik Ramena
el 16 de Mzo. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Axes Appearance 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!