필터 지우기
필터 지우기

Common left ylabel and right ylabel for subplots

조회 수: 42 (최근 30일)
Mayank Parmar
Mayank Parmar 2023년 6월 4일
댓글: Mayank Parmar 2023년 6월 4일
Hello,
I have a figure with 6 subplots in 2 rows and 3 columns. Each subplot has two y axes, first say "Y-1" and second, "Y-2". I want single ylabel on each side for the entire figure. I have following code that takes care of common ylabel on the left hand side:
fig = figure;
subplot(2, 3, 1)
...
subplot(2, 3, 6)
...
handle = axes(fig,'visible','off');
handle.XLabel.Visible='on';
handle.YLabel.Visible='on';
xlabel(handle, 'X')
ylabel(handle, 'Y-1')
For right hand common ylabel, I have tried using
yyaxis right
However, that doesn't work for me. Any help on this will be greatly appreciated.
Many thanks!

답변 (1개)

Harsh Kumar
Harsh Kumar 2023년 6월 4일
Hi Mayank ,
It is my understanding that you are unable to assign a common right ylabel for your multi axes graph using yylabel.This might be because there doesn,t exists a function like yylabel as i tried in matlab R2023a .
To resolve this issue, you may use the matlab inbuilt "yyaxis" OR "annotation" function of matlab to get the desired results .
For your reference, the below example demonstrates a simple approach to assign a common right label to a multi-axes graph using "annotation" function :
fig = figure;
% Subplot 1
subplot(2, 3, 1);
% ... code for subplot 1
% Subplot 6
subplot(2, 3, 6);
% ... code for subplot 6
% Create a common ylabel on the right side
annotation('textarrow', [0.91 0.91], [0.45 0.55], 'String', 'Y-1', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'Color', 'red', 'FontSize', 12);
% Adjust the figure's position to make room for the ylabel
fig.Position(3) = fig.Position(3) + 0.1;
  댓글 수: 3
Harsh Kumar
Harsh Kumar 2023년 6월 4일
편집: Harsh Kumar 2023년 6월 4일
Hi Mayank,
To my understanding , You can do it with 'yyaxis' as well but with a bit adjustment of label coordinates as 'yyaxis' unlike 'annotation' is function related to axis not plot/figure.
For your reference, the below example demonstrates a simple approach to assign a common right label to a multi-axes graph using 'yyaxis' function:
fig = figure;
% Subplot 1
subplot(2, 3, 1);
% ... code for subplot 1
% Subplot 6
subplot(2, 3, 6);
% ... code for subplot 6
% Set the right-hand y-axis label
yyaxis right;
ylabel('Y-1');
% Adjust the position and height of the right-hand y-axis label
h = get(gca, 'ylabel');
h.Position(1) = h.Position(1) + 0.1; % Adjust the x-coordinate as needed
h.Position(2) = h.Position(2) + 0.9; % Adjust the y-coordinate as needed
Mayank Parmar
Mayank Parmar 2023년 6월 4일
Hi Harsh,
I tried similar approach previously but in this case, 'ylabel' on the left hand side disappears. For now, I will stick with the annotations and fiddle with this problem when I have more time. I am not closing this question yet as I would like to come back to it with or for a solution that uses 'ylabel' to get labels on both sides.
Thank you for your patience!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by