Print to file, saveas, maintaining figure dimensions

조회 수: 28 (최근 30일)
Henry
Henry 2012년 8월 17일
Hello All,
I'm creating a single figure with three plots and setting the axes to be equal giving me three square plots (images, actually). This is all done many times with a loop so I'm looking for a coding solution rather than a clicking solution. To reduce the amount of blank space, I adjust the figure window size:
set(fig,'Position',[100 100 1200 300])
to give a rectangular window. When it is printed or saved to a file:
print(fig,'-djpeg','filename')
or
saveas(fig,'filename.extension')
the resulting saved image (jpeg) has the same dimensions as the default figure window. I've seen answers to similar problems that use:
set(fig,'PaperPosition', [100 100 1200 300])
but that didn't do the trick. In a sentence, I'm looking for the best way to save the figure as an image with specific dimensions. I'd appreciate any suggestions! Thank you.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 17일
편집: Azzi Abdelmalek 2012년 8월 17일
check this
t=0:0.1:10;y=sin(t)
plot(t,y);
set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperPosition', [0 0 10 15]); %x_width=10cm y_width=15cm
saveas(gcf,'fig1.tif')
%if it's for use with word, use the same units then word's
  댓글 수: 1
Henry
Henry 2012년 8월 18일
Thanks for your answer, it is most similar to what I was trying. The main difference is in the PaperUnits specification, and it works to accomplish my goal.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Oleg Komarov
Oleg Komarov 2012년 8월 17일
I suggest to use export_fig() from the FEX. It also crops the figure grey borders automatically.
% Load and display mandrill
load mandrill
image(X)
colormap(map)
axis off
% Change axis dimension ...
axis image
% ... or manually
set(gca,'units','pix','pos',[100,100,500,300])
% Export
export_fig('test.jpeg',gca)
  댓글 수: 1
Henry
Henry 2012년 8월 18일
Thanks for this, export_fig looks like a useful tool.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by