如何将绘图保存为PDF文件而周围没有很大的空白

如何将绘图保存为PDF文件而周围没有很大的空白

本文介绍了如何将绘图保存为PDF文件而周围没有很大的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我以 EPS 格式打印图表,则EPS文件的内容将被完全占用与情节.但是,如果我以 PDF 格式打印图表,则在图表的上方和下方都有很大的空白PDF文件.如何在打印图周围没有较大空白的情况下将打印图保存为PDF文件?

我的猜测是如何根据绘图大小自动在PDF文件中选择合适的纸张"大小进行打印.

这是我在 tex.stackexchange.com ,我在这里得到的答复大多试图解决 MATLAB以外的问题,而我仍然不太了解从MATLAB内部尝试解决的唯一答复.所以我想看看这里是否还有更多意见.

解决方案

适当大小"是什么意思? MATLAB 图形就像矢量图形一样,因此您基本上可以在绘图上选择所需的大小. /p>

您可以使用功能 设置 .

示例:

plot(epx(1:5));
set(gcf, 'PaperPosition', [0 0 5 5]); %Position plot at left hand corner with width 5 and height 5.
set(gcf, 'PaperSize', [5 5]); %Set the paper to have width 5 and height 5.
saveas(gcf, 'test', 'pdf') %Save figure

上面的代码将删除大多数边框,但不是全部.这是因为左上角(位置矢量中的[0 0])不是"true"左上角.要删除更多边框,可以调整PaperPositionPaperSize向量.

示例:

plot(exp(1:5))
set(gcf, 'PaperPosition', [-0.5 -0.25 6 5.5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
saveas(gcf, 'test', 'pdf')

If I print a plot in EPS format, the content of the EPS file is fully occupied with the plot. But if I print a plot in PDF format, then there are big margins above and below the plot in the PDF file. How can I save a plot in a PDF file without the big margin around the plot?

My guess is how to automatically choose the proper "paper" size in a PDF file to print to, according to the plot size.

This is a question I have asked at tex.stackexchange.com, where I have got replies which mostly tried to solve the problem outside MATLAB, and I still don't quite understand the only reply that tried to solve from within MATLAB. So I would like to see if there are more opinions here.

解决方案

What do you mean by "the proper size"? MATLAB figures are like vector graphics, so you can basically choose the size you want on your plot.

You can set the size of the paper and the position of the figure with the function set.

Example:

plot(epx(1:5));
set(gcf, 'PaperPosition', [0 0 5 5]); %Position plot at left hand corner with width 5 and height 5.
set(gcf, 'PaperSize', [5 5]); %Set the paper to have width 5 and height 5.
saveas(gcf, 'test', 'pdf') %Save figure

The above code will remove most of the borders, but not all. This is because the left-hand corner ([0 0] in the position vector) is not the "true" left-hand corner. To remove more of the borders, you can adjust the PaperPosition and PaperSize vectors.

Example:

plot(exp(1:5))
set(gcf, 'PaperPosition', [-0.5 -0.25 6 5.5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
saveas(gcf, 'test', 'pdf')

这篇关于如何将绘图保存为PDF文件而周围没有很大的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:45