Question

I'm plotting data from 9 different sources to a subplot in Matlab. Here you can see my figure:

enter image description here

Each row is representing results for a certain variable under different conditions. So row 1 is variable 1, second row variable 2 etc. Anyway, as you can see from the picture the center plot scales strangely in comparison with the other two in the second row.

The code I have used includes the use of commands such as: subplot(3,3,i), imagesc(data), colorbar, colormap(flipud(gray)), title('sometitle'), caxis([limits])

I tried to fix the center plot by setting the y-limits using ylim([0.5 3.5]), but this had no effect...when I tried ylim([0 4]) this happened:

enter image description here

Note that the data in the plots in each row have equal size matrices. In row 1: 7-by-7 matrix, in row 2: 3-by-3 matrix and in row 3: 4-by-4 matrix.

How can I resolve this issue? :)

Thank you for any help!

UPDATE:

Here is what happened after I tried using the commands:

subplot(3,3,5)
imagesc(data)
axis square
colorbar

enter image description here

Here is a minimum working example: (It apparently does not give exactly the same results, but still there is similar issues with it as well):

data11 = rand(7,7);
data12 = rand(7,7);
data13 = rand(7,7);
data21 = rand(3,3);
data22 = rand(3,3);
data23 = rand(3,3);
data31 = rand(4,4);
data32 = rand(4,4);
data33 = rand(4,4);
subplot(3,3,1)
imagesc(data11)
colorbar
colormap(flipud(gray))
title('title')
subplot(3,3,2)
imagesc(data12)
colorbar
colormap(flipud(gray))
title('title')
subplot(3,3,3)
imagesc(data13)
colorbar
colormap(flipud(gray))
title('title')
subplot(3,3,4)
imagesc(data21)
colorbar
title('title')
subplot(3,3,5)
imagesc(data22)
colorbar
title('title')
subplot(3,3,6)
imagesc(data23)
colorbar
title('title')
subplot(3,3,7)
imagesc(data31)
colorbar
title('title')
subplot(3,3,8)
imagesc(data32)
colorbar
title('title')
subplot(3,3,9)
imagesc(data33)
colorbar
title('title')

You should get something like this:

enter image description here

Notice that I inputted the commands individually (command + enter, command + enter, etc.) and then I get the problem, i.e. the picture you see in this post. If I copy and paste the whole code (whole code + enter) I don't get any problems...

Was it helpful?

Solution

I would first try to set the 'ActivePositionProperty' for each axis to 'Position' See the documentation on axes properties for details.

 h1 = subplot(3,3,1);
 set(h1,'ActivePositionProperty','Position');

 h2 = subplot(3,3,2);
 set(h2,'ActivePositionProperty','Position');

If that doesn't work you will need to set the position property for each plot manually.

 Margin = 0.1
 Width = 1 - 4*Margin;
 Height = 1 - 4*Margin;
 Left = [ (Margin) (2*Margin+Width) (3*Margin+2*Width) ];
 Bottom = [ (Margin) (2*Margin+Height) (3*Margin+2*Height) ];

 h1 = subplot(3,3,1);
 set(h1,'Position', [Left(1) Bottom(3) Width Height]);

 h2 = subplot(3,3,2);
 set(h1,'Position', [Left(2) Bottom(3) Width Height]);

 h3 = subplot(3,3,2);
 set(h1,'Position', [Left(3) Bottom(3) Width Height]);

 h4 = subplot(3,3,2);
 set(h1,'Position', [Left(1) Bottom(2) Width Height]);

 %Etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top