different locations of y-axes and ylabels in subplots
조회 수: 1 (최근 30일)
이전 댓글 표시
I have 4 subplots and I would like to have:
- all the 4 ylabel texts (here called as "first", "second", "third" and "fourth") perfectly aligned on the left of the figure
- the Y-Axis (i.e. the vertical line, plus yticks and the corresponding numbers/values) of the first and third subplots on the right side of the figure
Is it possible?
Here you are an attempt (does not fullfill conditions 1 and 2):
subplot(4,1,1);
x = linspace(0,10);
y1 = sin(x);
plot(x,y1)
ylabel('first')
hAxis = gca;
hAxis.YAxisLocation = 'right';
subplot(4,1,2);
y2 = sin(5*x);
plot(x,y2)
ylabel('second')
subplot(4,1,3);
x = linspace(0,10);
y1 = cos(x);
plot(x,y1)
ylabel('third')
hAxis = gca;
hAxis.YAxisLocation = 'right';
subplot(4,1,4);
y2 = sin(2*x);
plot(x,y2)
ylabel('fourth')
which results in:
My desired output is here represented:
댓글 수: 0
채택된 답변
Midhulesh Vellanki
2022년 5월 20일
편집: Midhulesh Vellanki
2022년 5월 20일
You can do something like the code below. please note that Ylabel is a child of YAxis that's why the label move along with the axis.
You can play with Positon proptery of label to further customize the behaviour.
subplot(4,1,1);
x = linspace(0,10);
y1 = sin(x);
plot(x,y1)
la1=ylabel('first');
old_values1 = la1.Position;
hAxis = gca;
hAxis.YAxisLocation = 'right';
la1.Position = [x(1)-0.7 old_values1(2) old_values1(3)];
box off;
subplot(4,1,2);
y2 = sin(5*x);
plot(x,y2)
la2=ylabel('second');
subplot(4,1,3);
x = linspace(0,10);
y1 = cos(x);
plot(x,y1)
la3=ylabel('third');
old_values3 = la3.Position;
hAxis = gca;
hAxis.YAxisLocation = 'right';
la3.Position = [x(1)-0.7 old_values3(2) old_values3(3)];
box off;
subplot(4,1,4);
y2 = sin(2*x);
plot(x,y2)
ylabel('fourth')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!