【问题标题】:How to set the plot in matlab to a specific size?如何将matlab中的绘图设置为特定大小?
【发布时间】:2011-11-25 14:16:43
【问题描述】:

一般来说,我希望将一个相当复杂的 x-y 图(很多重叠曲线)绘制成 A3 格式,所以:

A4 210x297  
A3 = A4*2 = 420 x 297  
... - 10mm each side = 400 x 277 (size of desired plot window)

设置绘图大小以使其在以 PDF(或任何其他常见输出格式)打印时适合该大小的最简单方法是什么?

【问题讨论】:

  • 嗨。我的回答够吗?
  • @Ionis - 还不能说。明天早上我必须在绘图仪上试一试,看看它是否真的有效。不过我一定会让你知道的。

标签: matlab printing plot export-to-pdf


【解决方案1】:

the matlab documentation for figure properties

即:

  • PaperSize - 明确定义画布的大小。
  • PaperType - 将 PaperSize 设置为几种标准纸张尺寸之一。

内置的绘图工具可让您将图形保存为各种图像格式,因此您应该很高兴。摆弄上述设置应该可以使您的图形成为正确的打印尺寸。

祝你绘图愉快!

【讨论】:

【解决方案2】:

下载export fig(需要Ghostscript)。

尝试运行:

 surf(peaks);title('voila');export_fig 'test.pdf';

使用 Adob​​e 打印 pdf 文件时,将“页面缩放”设置为“适合可打印区域”。

【讨论】:

  • 老实说,export_fig 有时会失败。我更喜欢另一个答案。
【解决方案3】:

正如@LewisNorton解释的那样,需要设置图中的Paper***properties。下面是生成尺寸为420 x 297 mm(A3 大小)的PDF 文件的示例,其中绘图和文件边框之间的边距分别为10 mm(上、下、左、右)。

%# centimeters units
X = 42.0;                  %# A3 paper size
Y = 29.7;                  %# A3 paper size
xMargin = 1;               %# left/right margins from page borders
yMargin = 1;               %# bottom/top margins from page borders
xSize = X - 2*xMargin;     %# figure size on paper (widht & hieght)
ySize = Y - 2*yMargin;     %# figure size on paper (widht & hieght)

%# create figure/axis
hFig = figure('Menubar','none');
plot([0 1 nan 0 1], [0 1 nan 1 0]), axis tight
set(gca, 'XTickLabel',[], 'YTickLabel',[], ...
    'Units','normalized', 'Position',[0 0 1 1])

%# figure size displayed on screen (50% scaled, but same aspect ratio)
set(hFig, 'Units','centimeters', 'Position',[0 0 xSize ySize]/2)
movegui(hFig, 'center')

%# figure size printed on paper
set(hFig, 'PaperUnits','centimeters')
set(hFig, 'PaperSize',[X Y])
set(hFig, 'PaperPosition',[xMargin yMargin xSize ySize])
set(hFig, 'PaperOrientation','portrait')

%# export to PDF and open file
print -dpdf -r0 out.pdf
winopen out.pdf

手头没有打印机,我使用虚拟screen ruler 来检查测量结果;只需使用您喜欢的查看器显示 PDF 文件,并将缩放级别设置为 100%(我使用的是 Sumatra PDF)。如果您想亲自尝试,请注意某些查看器 (Adobe Reader) 可能使用的自定义 DPI 与系统默认分辨率不匹配(我的是 96 像素/英寸)。

在这里您可以看到等于10mm 的底部和左侧边距。其他两个边距也是如此:

请注意,在上面的示例中,我使轴覆盖了整个图形(图中没有灰色区域)。默认情况下,MATLAB 会为刻度标签、轴标签、标题等留出一些空白空间。这当然与上面提到的边距不同,我假设你已经知道 :)

【讨论】:

    【解决方案4】:

    如果您想要自定义形状(例如,对于长而细的图或将正方形图包含在另一个文件中),请同时设置 PaperSizePaperPosition 选项。

    set(gcf, 'PaperSize', [30 10], 'PaperPosition', [0 0 30 10])
    print -pdf filename
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多