Reputation: 39
I try to set this subplot one after another, But cannot change their position. What can i do?
figure
subplot(10,1,1,'Position',[0.5,0.69,1,0.1]);plot(B{1, 1}(:,[1,3]),'Color',
[0,0,0]);legend('Black');
subplot(10,1,2,'Position',[0.5,0.37,1,0.1]);plot(B{2, 1}(:,[1,3]),'Color',
[1,0,0]);legend('Red');
subplot(10,1,3,'Position',[0,0,1,0.1]);plot(B{3, 1}(:,[1,3]),'Color',
[0,1,0]);legend('Lime');
subplot(10,1,4,'Position',[0,0,1,0.1]);plot(B{4, 1}(:,[1,3]),'Color',
[0,0,1]);legend('Blue');
subplot(10,1,5,'Position',[0,0,1,0.1]);plot(B{5, 1}(:,[1,3]),'Color',
[0,1,1]);legend('Cyan');
subplot(10,1,6,'Position',[0,0,1,0.1]);plot(B{6, 1}(:,[1,3]),'Color',
[1,0,1]);legend('Magenta');
subplot(10,1,7,'Position',[0,0,1,0.1]);plot(B{7, 1}(:,[1,3]),'Color',
[0.5,0.5,0.5]);legend('Gray');
subplot(10,1,8,'Position',[0,0,1,0.1]);plot(B{8, 1}(:,[1,3]),'Color',
[0.5,0,0]);legend('Maroon');
subplot(10,1,9,'Position',[0,0,1,0.1]);plot(B{9, 1}(:,[1,3]),'Color',
[0.5,0,0.5]);legend('Purple');
subplot(10,1,10,'Position',[0,0,1,0.1]);plot(B{10, 1}(:,[1,3]),'Color',
[0,0.5,0.5]);legend('Teal');
Upvotes: 1
Views: 3226
Reputation: 541
Well, you can change the position, as long as you do it properly.
As stated in the manual of the subplot, you can specify the position:
by using
subplot(m,n,p)
Which uses the m
x n
grid plotting in the p
position. This is what you partially used.
by using
subplot('Position',[left bottom width height])
And this is where you have a problem. As it states in the manual, if it overlap, it will erase the graph that is under.
In your case, several of the positions are overlapping.
Note also that the positions are always normalized, so left=0.5
with a width=1
means that you cropped half of the figure in the x direction. Pay attention when you use manual positioning.
As Cris Luengo's answer pointed out, you can use axis
directly. Which has a few pros and cons. However the unit in axis
are also normalized. So, know what you are using.
When you use both (manual and automatic) settings, it is not clear to me which one will have preferences, as i got different outputs when i tested a part of your code.
Upvotes: 3
Reputation: 60444
If you are going to set their position by hand, just create the axes objects directly:
figure
axes('Position',[0.5,0.69,1,0.1]);plot(B{1, 1}(:,[1,3]),'Color',
[0,0,0]);legend('Black');
axes('Position',[0.5,0.37,1,0.1]);plot(B{2, 1}(:,[1,3]),'Color',
[1,0,0]);legend('Red');
The nice thing about subplot
is that it places the axes for you. It has no other purpose.
Upvotes: 2