On Nov 3, 6:45 am, "Emma Robertson" <m...@hotmail.co.uk> wrote:
> yes, I meant subplots instead of subfigures (switching between matlab and latex !)
>
> I spent all day today trying to figure out how you would do this. It works perfectly fine with Figures but I can't make it do the same thing with Subplots included.
>
> ****************** Here's what you'd do for a figure *****************
> E.g.,
> x = pi:.1:pi;
> y = sin(x);
> h=figure;
> plot(x,y)
> colormap(jet)
> % Make your figure boundaries tight:
> ti = get(gca,'TightInset');
> set(gca,'Position',[ti(1) ti(2) 1ti(3)ti(1) 1ti(4)ti(2)]);
>
> % Now you have a tight figure on the screen but if you directly do saveas
> % (or print), MATLAB will still add the annoying white space. To get rid
> % of them, we need to adjust the ``paper size":
> set(gca,'units','centimeters')
> pos = get(gca,'Position');
> ti = get(gca,'TightInset');
>
> set(gcf, 'PaperUnits','centimeters');
> set(gcf, 'PaperSize', [pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
> set(gcf, 'PaperPositionMode', 'manual');
> set(gcf, 'PaperPosition',[0 0 pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
> %Done! Now you can saveas your figure:
> saveas(h,'output.pdf');
>
> ********* Here's my attempt to do the same for a figure with subplots ************
>
> figure(2)
> h1=subplot(3,2,1);
> pcolor(a1,b1,c1);colorbar;shading flat
> t1=get(h1,'TightInset');
> p1=get(h1,'Position');
> set(gca,'Position',[t1(1) t1(2) 1t1(3)ti(1) 1t1(4)t1(2)]);
> set(gca,'units','centimeters')
> set(gcf, 'PaperUnits','centimeters');
> set(gcf, 'PaperSize', [p1(3)+t1(1)+t1(3) p1(4)+t1(2)+t1(4)]);
> set(gcf, 'PaperPositionMode', 'manual');
>
> %%
> h2=subplot(3,2,2);
> pcolor(a1,b1,c1);colorbar;shading flat
> t2=get(h2,'TightInset');
> p2=get(h2,'Position');
> set(gca,'units','centimeters')
> set(gcf, 'PaperUnits','centimeters');
> set(gcf, 'PaperSize', [p2(3)+t2(1)+t2(3) p2(4)+t2(2)+t2(4)]);
> set(gcf, 'PaperPositionMode', 'manual');
>
> %%
> h3=subplot(3,2,3);
> pcolor(a1,b1,c1);colorbar;shading flat
> t3=get(h3,'TightInset');
> p3=get(h3,'Position');
> set(gca,'units','centimeters')
> set(gcf, 'PaperUnits','centimeters');
> set(gcf, 'PaperSize', [p3(3)+t3(1)+t3(3) p3(4)+t3(2)+t3(4)]);
> set(gcf, 'PaperPositionMode', 'manual');
>
> and so on ..... for the rest of the subplots.
>
> I think the problem is in set(gca,'Position',..) AND/OR set(gcf, 'PaperSize',......).
>
> Please can someone help ... I have already spent a whole day on this  I'm not going to have more time to figure this out.
>
> Any help is greatly appreciated.
I think you should ditch subplot and start from scratch.
A figure (however you define its size) goes from 0 to 1 in both
directions with the origin at the bottom left.
So, you can lay out your figure containing several panels using axes:
% Bottom left
axes('Position',[left bottom width height])
plot(x,y)
% Bottom right
axes('Position',[left+width+gapx bottom width height])
plot(x1,y1)
% Top left
axes('Position',[left bottom+gapy+height width height])
% Top right
axes('Position',[left+width+gapx bottom+gapy+height width height])
Now you have complete control of where your panels sit in the figure.
For example, if the x axes are common, you can move the top panels
close to the top of the bottom panels (by reducing gapy) and omit the
x tick labels (using set(gca,'XTickLabel','')).
