如何将matlab中的绘图设置为特定大小?

发布于 2024-12-06 12:14:12 字数 228 浏览 0 评论 0原文

一般来说,我希望将相当复杂的 xy 图(大量重叠曲线)绘制为 A3 格式,因此:

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

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

Generally, I wish to plot a rather complex x-y plot (lots of overlapping curves) to an A3 format so:

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

What is the easiest way to set the size of the plot so it fits that size when printed in PDF (or any other common output format)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青柠芒果 2024-12-13 12:14:12

正如 @LewisNorton 所解释的,您需要设置 Paper*** 图形的属性。下面是生成尺寸 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

screenshot_MATLAB
screenshot_PDF

由于手头没有打印机,我正在使用虚拟 屏幕标尺来检查测量值;只需使用您喜欢的查看器显示 PDF 文件,并将缩放级别设置为 100%(我使用苏门答腊 PDF)。如果您想自己尝试一下,请注意某些查看器 (Adobe Reader) 可能使用与系统默认分辨率不匹配的自定义 DPI(我的分辨率为 96 像素/英寸)。

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

margins_1cm

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

As @LewisNorton explained, you need to set the Paper*** properties of the figure. Below is an example for producing a PDF file with dimensions 420 x 297 mm (A3 size), where the margins between the plot and the file borders are 10 mm each (top,bottom,left,right).

%# 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

screenshot_MATLAB
screenshot_PDF

Without a printer at hand, I am using a virtual screen ruler to check the measurements; Simply display the PDF file with your preferred viewer, and the set the zoom level at 100% (I am using Sumatra PDF). If you want to try this yourself, just be aware that some viewers (Adobe Reader) might be using a custom DPI not matching the system default resolution (mine at 96 pixels/inch).

Here you can see the bottom and left margins equal to 10mm. The same holds for the other two margins:

margins_1cm

Note that in the example above, I made the axis cover the entire figure (no gray area in the figure). By default, MATLAB leaves some empty space for tick labels, axis labels, title, etc.. This is of course different from the margins mentioned above, which I assume you already know :)

迷乱花海 2024-12-13 12:14:12

请参阅有关图窗属性的 matlab 文档

即:

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

内置的绘图工具可让您将图形保存为各种图像格式,因此您应该可以开始使用了。摆弄上述设置应该可以使您的图形达到正确的打印尺寸。

快乐的阴谋!

See the matlab documentation for figure properties.

Namely:

  • PaperSize - Explicitly defines the size of the canvas.
  • PaperType - Sets PaperSize to one of several standard paper sizes.

The built in plot tool lets you save figures as all sorts of image formats so you should be good to go. Fiddling with the above settings should get your figure to be the correct size for printing.

Happy plotting!

千里故人稀 2024-12-13 12:14:12

下载导出Fig(需要Ghostscript)。

尝试运行:

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

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

Download export fig(Requires Ghostscript).

Try running:

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

When using Adobe to print the pdf file, set 'Page Scaling' to 'Fit to Printable Area'.

我爱人 2024-12-13 12:14:12

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

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

If you want a custom shape (e.g. for a long, thin plot or for a square plot to include in another file), set both the PaperSize and PaperPosition options.

set(gcf, 'PaperSize', [30 10], 'PaperPosition', [0 0 30 10])
print -pdf filename
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文