MATLAB Answers

Inconsistent figure width on the screen (and exported)

15 views (last 30 days)
Léopold
Léopold on 24 May 2017
Commented: Léopold on 24 May 2017
Hello everyone,
I am facing a strong problem regarding exact figure width. A priori, I am familiar with the usual commands, here is my code :
% Screen size
set(0,'units','centimeters');
ss = get(0,'screensize');
widthScreen = ss(3);
heightScreen = ss(4);
% Fig
widthFig = 10.0;
heightFig = 5;
posFig = [0.5*(widthScreen-widthFig) 0.5*(heightScreen-heightFig)...
widthFig heightFig];
figure(1);
set(gcf,'Color','w');
set(gcf,'units','centimeters',...
'Position',posFig);
set(gcf,'PaperUnits','centimeters',...
'PaperSize', [widthFig heightFig],...
'PaperPosition',[0 0 widthFig heightFig]);
set(gcf,'PaperPositionMode','auto');
plot(t/milli,x_all/milli,'LineWidth',1);
% ...
When I run my code and measure the figure width on the screen, it is always something like ~9.1cm. Using the following lines
pos = get(gcf, 'Position');
width = pos(3)
Ouput is 10.020088854166666
All of this is really strange. What am I doing wrong? Up to now, I have used this very useful codes to export figures already sized in cm, but I actually figured out that the size is not correct.
Thanks forward for your help.

Answers (1)

Jan
Jan on 24 May 2017
Do you create the output using print and e.g. the PDF or EPS format? Then the size on the screen does not matter at all, because the PaperSize is used. In this case you do not have to care about the size of the figure on the screen.
Note that the DPI value used by the operating system (an provided to Matlab) need not be exactly, what the monitor shows. If the pixels on the monitor are slightly larger or if you use a display magnification in the OS differing from 100% the sizes will differ.
So please explain, what you want to achieve. How do you export the figures and why to the appearance on the screen matter?
  1 Comment
Léopold
Léopold on 24 May 2017
Hello Jan,
Thanks for your answer.
Indeed I want in the end to export the figure in eps using to following command
saveas(gcf,strFig,'epsc');
This story of appearance/size on the screen was just a sanity check let's say, we can forgot about it.
The figures are dedicated to a scientific publication and my goal is obviously to pre-scale the figures directly in Matlab and to include them in a Latex document without scaling ("scale=1").
When measuring the figure width within latex, obtained size is 9.31cm. Note that this obtained width seems to depend from one figure to another, depending on the axis, the label,...
Thanks forward.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by