How to add a shared ylabel on the right hand-side of a figure, when combining tiledlayout and yyaxis?
In addition to a shared ylabel on the left hand-side of a figure, I want to put a shared ylabel on the right hand-side of the tiledlayout, when also using yyaxis. How can I achieve this? I have prepared the following MWE:
figure
t = tiledlayout(4,1);
for i = 1:4
nexttile
title("Tile"+i)
yyaxis left
plot(rand(1,10))
yyaxis right
plot(rand(1,10))
end
title(t,"Tiles")
xlabel(t,"x")
ylabel(t,"y left")
% ylabel(t,"y right")
Thanks in advance!
Edit:
My yticklabels on the left as well as on the right hand-side are relatively long, therefore, both shared ylabels need to factor the necessary distance in. The shared ylabel on the left hand-side does this automatically, the one on the right hand-side should do the same. I have updated the MWE (unfortunately, it now acts a bit buggy but it should illustrate the point, nonetheless):
figure
t = tiledlayout(4,1);
longYTickLabels_left = ["negative yticklabel left" "0" "positive yticklabel left" ];%edit: added
longYTickLabels_right = ["negative yticklabel right" "0" "positive yticklabel right"];%edit: added
for i = 1:4
nexttile
title("Tile"+i)
yyaxis left
plot(rand(1,10))
yticklabels(longYTickLabels_left)%edit: added
yyaxis right
plot(rand(1,10))
yticklabels(longYTickLabels_right)%edit: added
end
title(t,"Tiles")
xlabel(t,"x")
ylabel(t,"y left")
% ylabel(t,"y right")In addition to a shared ylabel on the left hand-side of a figure, I want to put a shared ylabel on the right hand-side of the tiledlayout, when also using yyaxis. How can I achieve this? I have prepared the following MWE:
figure
t = tiledlayout(4,1);
for i = 1:4
nexttile
title("Tile"+i)
yyaxis left
plot(rand(1,10))
yyaxis right
plot(rand(1,10))
end
title(t,"Tiles")
xlabel(t,"x")
ylabel(t,"y left")
% ylabel(t,"y right")
Thanks in advance!
Edit:
My yticklabels on the left as well as on the right hand-side are relatively long, therefore, both shared ylabels need to factor the necessary distance in. The shared ylabel on the left hand-side does this automatically, the one on the right hand-side should do the same. I have updated the MWE (unfortunately, it now acts a bit buggy but it should illustrate the point, nonetheless):
figure
t = tiledlayout(4,1);
longYTickLabels_left = ["negative yticklabel left" "0" "positive yticklabel left" ];%edit: added
longYTickLabels_right = ["negative yticklabel right" "0" "positive yticklabel right"];%edit: added
for i = 1:4
nexttile
title("Tile"+i)
yyaxis left
plot(rand(1,10))
yticklabels(longYTickLabels_left)%edit: added
yyaxis right
plot(rand(1,10))
yticklabels(longYTickLabels_right)%edit: added
end
title(t,"Tiles")
xlabel(t,"x")
ylabel(t,"y left")
% ylabel(t,"y right") In addition to a shared ylabel on the left hand-side of a figure, I want to put a shared ylabel on the right hand-side of the tiledlayout, when also using yyaxis. How can I achieve this? I have prepared the following MWE:
figure
t = tiledlayout(4,1);
for i = 1:4
nexttile
title("Tile"+i)
yyaxis left
plot(rand(1,10))
yyaxis right
plot(rand(1,10))
end
title(t,"Tiles")
xlabel(t,"x")
ylabel(t,"y left")
% ylabel(t,"y right")
Thanks in advance!
Edit:
My yticklabels on the left as well as on the right hand-side are relatively long, therefore, both shared ylabels need to factor the necessary distance in. The shared ylabel on the left hand-side does this automatically, the one on the right hand-side should do the same. I have updated the MWE (unfortunately, it now acts a bit buggy but it should illustrate the point, nonetheless):
figure
t = tiledlayout(4,1);
longYTickLabels_left = ["negative yticklabel left" "0" "positive yticklabel left" ];%edit: added
longYTickLabels_right = ["negative yticklabel right" "0" "positive yticklabel right"];%edit: added
for i = 1:4
nexttile
title("Tile"+i)
yyaxis left
plot(rand(1,10))
yticklabels(longYTickLabels_left)%edit: added
yyaxis right
plot(rand(1,10))
yticklabels(longYTickLabels_right)%edit: added
end
title(t,"Tiles")
xlabel(t,"x")
ylabel(t,"y left")
% ylabel(t,"y right") tiledlayout, yyaxis, ylabel, figure MATLAB Answers — New Questions









