How can I save my figure to eps AND keep white margins (from my defined figure and axes position)?

조회 수: 6 (최근 30일)
I am producing multiple figures which I then need to vertically align in latex. I set my figure and axes position like this:
% Set figure total dimension
set(gcf,'Units','centimeters')
set(gcf,'Position',[0 0 4.5 5.8])
% Set size and position of axes plotting area within figure dimensions. To
% keep vertical axes aligned for multiple figure keep the horizontal
% position consistent
set(gca,'Units','centimeters')
set(gca, 'Position',[1.5 1.3 2.85 4])
Some of my figures have a ylabel and some don't, which thanks to the above set position does not affect the format of the figure. However when I save my figure to eps using
saveas(gcf,'filename','epsc')
the eps file saves it as the tightest fit, ignoring my set positions. How can I get it to save whilst conserving my set formatting?
I've tried saving to .png but the quality is massively reduced (even when using the package export_fig). Is there a simple solution?
I am on MacOs.

채택된 답변

Jatin
Jatin 2024년 8월 23일
Hi @Zoe,
If we go through the documentation of “Printing and Exporting” property of figure then we can see that we should use PaperPosition” and “PaperUnits” as properties rather than “Position” and “Units” for the figure object while printing or exporting.
Updating your code as below should give you the desired results:
% Set figure total dimension
set(gcf,'PaperUnits','centimeters')
set(gcf,'PaperPosition',[0 0 4.5 5.8])
You can also go through the following MATLAB Answer and MathWorks documentation for more information on “Printing and Exporting” property of figure:
  댓글 수: 2
Zoe
Zoe 2024년 8월 23일
Thank you so so much!! I have been stuck on this for days.
Also in case anyone else has a similar problem, I found that then putting my axes units into normalised allowed me to create the figure I wanted, for some reason my paperunits in centimetres did not match well with axes units in centimetres.
I can't thank you enough. I now actually have hope that my thesis will look nice!!
Zoe
Zoe 2024년 8월 23일
Hi again @Jatin Singh, it appears I am still struggling with this after all... As soon as I remove a label, my axes no longer align the way I've prescribed in the axes environment which messes up the alignement in my latex document... do you have any suggestions for this?

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by