MATLAB:将图形打印为 pdf,如 MATLAB 中所示
我正在尝试将图形导出(另存为、打印)为 .pdf 格式。然而,无论我如何配置设置,图形周围都有很大的边距。
当我将图形导出为 .eps 格式时,就没有这样的问题 --- 即图形看起来就像在 MATLAB 中显示的一样。
如何将图形导出为 .pdf 格式,使其看起来与 MATLAB 中显示的相同?
I am trying to export (save as, print) a figure into .pdf format. However, no matter how I configure the setting, there are large margins around the figure.
When I export the figure into .eps format, there is no such problem --- i.e. the figure just looks like it is displayed in the MATLAB.
How could I export the figure into .pdf format, which looks the same as it is shown in the MATLAB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过在绘图命令后立即添加以下代码行来自动执行上述过程。
前两行测量您身材的尺寸(以英寸为单位)。下一行配置打印纸张尺寸以适合图形尺寸。最后一行使用
print
命令并导出矢量 pdf 文档作为输出。You can automate the process above by adding the following lines of code immediately after the plot command.
The first two lines measure the size of your figure (in inches). The next line configures the print paper size to fit the figure size. The last line uses the
print
command and exports a vector pdf document as the output.您可以尝试以下操作:
1) 在 MATLAB 中绘制图形后,转到“File- >“导出设置”,然后输入所需输出的大小。例如,宽度:6 英寸,高度:5 英寸。然后单击“应用到图”按钮。
2) 不要关闭“导出设置”窗口。进入“文件->打印预览->纸张”,在宽度和高度选项中输入相同的尺寸。
3) 不要关闭“打印预览”窗口。返回“导出设置”窗口,单击“导出”,然后选择 pdf 格式并保存。
4)检查输出的PDF文件,你会发现它是完美的。
我在博客文章 Export 中找到了解决方案在 MATLAB 中将图形转换为 PDF。
You can try the following:
1) After you plot the figure in MATLAB, go to 'File->Export Setup', and input the size of the output you want. For example, Width: 6 inches, Height: 5 inches. Then click 'Apply to Figure' button.
2) Don't close the 'Export Setup' window. Go to 'File->Print Preview->Paper', input the same size in the Width and Height options.
3) Don't close the 'Print Preview' window. Go back to the 'Export Setup' window, and click 'Export', then select pdf format and save it.
4) Check the output PDF file, you'll see it is perfect.
I found the solution in blog post Export figure to PDF in MATLAB.
2 行脚本,用于在横向 A4 中导出为 PDF(假设您的绘图是“当前图形”):
%---------------------------- ------------------------------------------
% 将纸张大小调整为横向-A4并相应地重新定位图形
set( gcf,'PaperSize',[29.7 21.0], 'PaperPosition',[0 0 29.7 21.0])
% 导出到 PDF 文件 'YourFileName.pdf'
print -dpdf 'YourFileName'
%----- -------------------------------------------------- ------------
任何其他调整:检查图形属性 - 只需在命令窗口上“get( gcf )”
2-lines script, for exporting to PDF in landscape A4 (assuming your plot is the "current figure"):
%-------------------------------------------------------------------
% resize paper as a landscape-A4 and reposition figure accordingly
set( gcf,'PaperSize',[29.7 21.0], 'PaperPosition',[0 0 29.7 21.0])
% export to PDF file 'YourFileName.pdf'
print -dpdf 'YourFileName'
%-------------------------------------------------------------------
Any other tweak : check the Figure properties - simply "get( gcf )" on the command window