ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Matlab绘图基础——用print函数批量保存图片到文件(Print figure or save to file)

2022-02-19 15:01:59  阅读:336  来源: 互联网

标签:figure PostScript print Matlab file formats Print 图片


Matlab绘图基础——用print函数批量保存图片到文件(Print figure or save to file)

 

一、用法解析

1.1. 分辨率-rnumber

1.2.  输出图片的“格式”formats

二、用法示例

2.1. 设置输出图片的“图像纵横比”

2.2. Batch Processing(图片保存“批处理”)filename

1.2. 输出图片的“格式”formats

一、用法解析

print(figure_handle,'formats','-rnumber','filename') 

%将图形保存为formats格式,分辨率为600的(默认为72),最好指定的分辨率大一点,否则保存图形的效果较差.

1.1. 分辨率-rnumber

Use -rnumber to specify the resolution of the generated output.

To set the resolution(分辨率) of the output file for a built-in MATLAB format, use the -r switch.

l  For example, -r300 sets the output resolution to 300 dots per inch(每英寸300个点)

The –r switch is also supported for Windows Enhanced Metafiles(增强型图元文件), JPEG, TIFF and PNG files, but is not supported for Ghostscript raster formats(栅格文件).

l  For more information, see Printing and Exporting without a DisplayandResolution Considerations.

—— 来自matlab帮助“print”页中

1.2.  输出图片的“格式”formats

请参考本文末尾

二、用法示例

% Save the figure with the handle h to a PostScript file named Figure1, which can be printed later.

H = figure;   % 指定图片打印figure_handles

% 若没有figure_handle,则默认print当前显示图片

plot(1:4,5:8)

print(h,'-dpng','-r200','Figure1')      % 这三行代码就够用了

2.1. 设置输出图片的“图像纵横比”

When you set the axes Position to [0 0 1 1] so that it fills the entire figure, the aspect ratio is not preserved when you print because MATLAB printing software adjusts the figure size when printing according to the figure's PaperPositionproperty. To preserve the image aspect ratio(图像纵横比) when printing, set the figure's 'PaperPositionMode' to 'auto' from the command line.

set(gcf,'PaperPositionMode','auto')

% Setting the current figure's (gcf) PaperPositionMode to auto enables

% you to resize the figure window and print it at the size you see on the screen.

举例

surf(peaks);shading interp           % 画图,shading使图像美观

axis off                                 % 不显示坐标轴

set(gcf,'PaperPositionMode','auto'); % 设置图像纵横比

print('-dpng','-r200','a');           % 保存图片,名为a

——来自matlab帮助 Printing Images

2.2. Batch Processing(图片保存“批处理”)filename

You can use the function form of print to pass variables containing file names. For example, this for loop uses file names stored in a cell array to create a series of graphs and prints each one with a different file name:

fnames = {'file1', 'file2', 'file3'};

for k=1:length(fnames)

    surf(peaks);shading interp

    print('-dtiff','-r600',fnames{k}) % fnames is a cell of string arrays so each element is a string

end

————来自matlab帮助“print”页末

注:如果你不能调整输出分辨率和文件格式,可能是"Printing and Exporting without a Display"问题,具体查看帮助“print”页

 

选项向量图形格式对应的文件扩展名
'-dpdf' 整页可移植文档格式 (PDF) 颜色 .pdf
'-deps' PostScript (EPS) 3 级黑白 .eps
'-depsc' 封装的 PostScript (EPS) 3 级彩色 .eps
'-deps2' 封装的 PostScript (EPS) 2 级黑白 .eps
'-depsc2' 封装的 PostScript (EPS) 2 级彩色 .eps
'-dmeta' 增强型图元文件(仅限 Windows®) .emf
'-dsvg' SVG(可伸缩向量图) .svg
'-dps' 全页 PostScript (PS) 3 级黑白 .ps
'-dpsc' 全页 PostScript (PS) 3 级彩色 .ps
'-dps2' 全页 PostScript (PS) 2 级黑白 .ps
'-dpsc2' 全页 PostScript (PS) 2 级彩色 .ps

 

引自:司徒鲜生

博客地址:Matlab绘图基础——用print函数批量保存图片到文件(Print figure or save to file) - 司徒鲜生 - 博客园 (cnblogs.com)

标签:figure,PostScript,print,Matlab,file,formats,Print,图片
来源: https://www.cnblogs.com/dhui-w/p/15912598.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有