Huge white space around the plot after saving

조회 수: 11 (최근 30일)
BN
BN 2020년 8월 11일
댓글: Image Analyst 2020년 8월 11일
Hi all,
Unfortunately, after save my figure and paste it in the Microsoft office word I see there is a huge white space around it. I want to make this white space as minimal as possible. I also read the page for saving figures with minimal white space but since I need to save it as -SVG It doesn't help me.
Here is my code:
CC_1 = rand(17, 8);
yvalues = {'Jan.','Feb.','Mar.','Apr.','May','Jun.','Jul.','Aug.','Sep.','Oct.','Nov.','Dec.','Winter','Spring',...
'Summer','Autumn','Annual'};
xvalues = {'model1','model2','model3','model4','model5','model6','model7','model8'};
h = heatmap(xvalues,yvalues,CC_1);
% Temporarily change axis units
% (from https://www.mathworks.com/matlabcentral/answers/481666-heatmap-chart-depict-squares-rather-than-rectangles#answer_393143)
originalUnits = h.Units; % save original units (probaly normalized)
h.Units = 'centimeters'; % any unit that will result in squares
% Get number of rows & columns
sz = size(h.ColorData);
% Change axis size & position;
originalPos = h.Position;
% make axes square (not the table cells, just the axes)
h.Position(3:4) = min(h.Position(3:4))*[1,1];
if sz(1)>sz(2)
% make the axis size more narrow and re-center
h.Position(3) = h.Position(3)*(sz(2)/sz(1));
h.Position(1) = (originalPos(1)+originalPos(3)/2)-(h.Position(3)/2);
else
% make the axis size shorter and re-center
h.Position(4) = h.Position(4)*(sz(1)/sz(2));
h.Position(2) = (originalPos(2)+originalPos(4)/2)-(h.Position(4)/2);
end
% Return axis to original units
h.Units = originalUnits;
% save figure
set(gcf,'PaperOrientation','landscape');
set(gcf,'PaperUnits','normalized')
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, .4, .6]);
print(gcf,'CC_ALL','-dsvg');
And here is the figure
Please let me know if there is any way to eliminate white space around my figure since I have more than 60 figures.
Thank you so much

채택된 답변

Image Analyst
Image Analyst 2020년 8월 11일
Try exportgraphics() instead of print().
  댓글 수: 2
BN
BN 2020년 8월 11일
편집: BN 2020년 8월 11일
Thank you, unfortunately I got this error:
Error using exportgraphics
File format 'svg' is not valid for export.
After using:
ax = gca;
exportgraphics(ax,'C_ALL.svg')
Image Analyst
Image Analyst 2020년 8월 11일
Then try export_fig().

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by