Emma Robertson
unread,Nov 2, 2011, 1:45:28 PM11/2/11You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
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) 1-ti(3)-ti(1) 1-ti(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) 1-t1(3)-ti(1) 1-t1(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.