Inconsistent figure width on the screen (and exported)
13 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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?
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!