如何将绘图保存到

如何将绘图保存到

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

问题描述

如果我以 EPS 格式打印绘图,则 EPS 文件的内容已被完全占用随着情节.但是,如果我以 PDF 格式打印图,则图的上方和下方都有很大的边距PDF 文件.如何将绘图保存在 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?

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

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

这是我在 tex.stackexchange.com,我在那里得到的回复大多试图解决 MATLAB 之外的问题,我仍然不太明白试图从 MATLAB 内部解决的唯一答复.所以想看看这里有没有更多的意见.

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.

推荐答案

合适的尺寸"是什么意思?MATLAB 图形就像矢量图形,因此您基本上可以在绘图中选择所需的大小.

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.

示例:

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])不是真正的"左角.要移除更多边框,您可以调整 PaperPositionPaperSize 向量.

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.

示例:

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 文件中而周围没有大边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:04