Size of exported pdf with given font size

23 次查看(过去 30 天)
Hi, I encountered a (hopefully) simple problem. I am exporting a figure to .pdf and I can't figure out how to scale the image before exporting. Of course I could scale the final .pdf, but then the font size isn't 12pt anymore! An important boundary condition is that I use LaTeX labels and ticks, e.g.:
xlabel('$x\ (\mathrm{m})$','Interpreter','LaTex','FontSize',12);
The final .pdf is about twice as large as I need, any tips how to make the axis resolution smaller please? Thank you!

回答(2 个)

Iain
Iain 2013-5-30
When using report generator to make pdfs, I have found that changing the "Paperposition" property of the figure changes the size on my resultant pdf files.
  3 个评论
Iain
Iain 2013-5-30
You can force an axis to work on a specific scale using the "axis" command. You can force an axis to have a specific aspect ratio and size by controlling it's position.
I'd need to have a play to figure out anything better.
Oliver Woodford
Oliver Woodford 2013-6-19
Jan: The export_fig help text states very clearly that the figure is exported as it appears on screen. So if you set the figure dimensions to the size you want it exported to you won't have any problems using export_fig.

请先登录,再进行评论。


José-Luis
José-Luis 2013-5-30
编辑:José-Luis 2013-5-30
How about setting the size of the figure programatically:
h = plot(rand(10,1));
xlabel('$x\ (\mathrm{m})$','Interpreter','LaTex','FontSize',12);
options.units = 'centimeters';
options.FontMode = 'Fixed'; %This line and next are the important bit
options.FixedFontSize = 12;
options.Width = 20;
options.Height = 20;
options.format = 'pdf'; %or whatever options you'd like
options.FontName = 'arial';
options.Renderer = 'painters';
hgexport(gcf,'your_plot.pdf',options);
  2 个评论
Jan
Jan 2013-5-30
编辑:Jan 2013-5-30
Hi, thank you for the tip, I didn't know about hgexport and I'm trying what it can do now. The first thing i noticed is a bit strange, compare: Result from "saveas":
Result from "hgexport":
There seems to be something wrong, maybe the aspect ratio. It is an interesting option to export figures, but the problems mentioned in my comment to Iain's answer remain.
José-Luis
José-Luis 2013-5-30
编辑:José-Luis 2013-5-30
The differences in the two plots might also be due to the renderer you chose.
Plotting figures in Matlab is a bit of a nightmare, if you modify one property, say the width, then other things will be changed and it will be hard to control the final output. Say you are interested in the paper size, the width of the figure and the aspect ratio. You can set these values and set the properties accordingly:
fH = figure;
h = axes;
lH = plot(1:10,1:10);
xlabel('$x\ (\mathrm{m})$','Interpreter','LaTex','FontSize',12);
%Sizes in cm
myPaperSize = [12 20];
width = 8;
widthLengthRatio = 0.5;
lowerLeft = [2 2];
set(fH,'PaperUnits','centimeters');
set(fH,'PaperPositionMode','manual');
set(fH,'PaperSize',myPaperSize);
set(fH,'Units','centimeters');
set(fH,'Position',[lowerLeft myPaperSize]);
set(h,'Units','centimeters');
set(h,'Position',[lowerLeft width width/widthLengthRatio]);
options.units = 'centimeters';
options.FontMode = 'Fixed';
options.FixedFontSize = 12;
options.format = 'pdf';
options.FontName = 'arial';
options.Renderer = 'painters';
hgexport(gcf,'your_plot.pdf',options);
To answer your comments:
  1. You can specify the width and get the height using the method above.
  2. What do you mean the axes scales to be the same? The XLim and YLim to be equal? If that is the case it is just a matter of set(). The ratio between the scale of the x's and the y's to be some value? In that case, DataAspectRatio (axes properties) would work if you don't care about the position of your axes. If you do, then you have to set your XLim, YLim, and Position manually so you have the required ratio.

请先登录,再进行评论。

类别

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