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!