matlab的图像输出,科学网—输出 Matlab 图形的一个方法 - 雷锦志的博文

经常看到有些人用 Matlab 画图后保存为 EPS 格式或者 PNG 格式的图时字体太小。不太美观。

这里把我常用的比较好方法和大家分享一下,也给自己和学生留个印记。

附件的 exportfig.m 程序可以很好地把 Matlab 画的图输出为很多格式的文件,并且可以设置字体的大小,颜色等,

使用方便灵活。

用法很简单, 把这个文件放在 Matlab 的搜索目录中(最简单就是当前的工作目录)。

然后:

fig=figure(1);  % 定义一个 fig 的图形句柄

..

..     % 这里用 plot 等函数画图

..

exportfig(fig, 'fig2.eps', 'FontMode', 'fixed','FontSize', 10, 'color', 'cmyk' );  % 把上面画的图(句柄为 fig )保存为 fig2.eps, 字号为 10,彩色。

运行以后就可以在当前目录看到一个名为 fig2.eps 的文件了。

这个 exportfig() 函数含有很多选项可以灵活设置,详看下面的说明:

%EXPORTFIG  Export a figure to Encapsulated Postscript.

%   EXPORTFIG(H, FILENAME) writes the figure H to FILENAME.  H is

%   a figure handle and FILENAME is a string that specifies the

%   name of the output file.

%

%   EXPORTFIG(...,PARAM1,VAL1,PARAM2,VAL2,...) specifies

%   parameters that control various characteristics of the output

%   file.

%

%   Format Paramter:

%     'Format'  one of the strings 'eps','eps2','jpeg','png','preview'

%          specifies the output format. Defaults to 'eps'.

%          The output format 'preview' does not generate an output

%          file but instead creates a new figure window with a

%          preview of the exported figure. In this case the

%          FILENAME parameter is ignored.

%

%     'Preview' one of the strings 'none', 'tiff'

%          specifies a preview for EPS files. Defaults to 'none'.

%

%   Size Parameters:

%     'Width'   a positive scalar

%          specifies the width in the figure's PaperUnits

%     'Height'  a positive scalar

%          specifies the height in the figure's PaperUnits

%

%     Specifying only one dimension sets the other dimension

%     so that the exported aspect ratio is the same as the

%     figure's current aspect ratio.

%     If neither dimension is specified the size defaults to

%     the width and height from the figure's PaperPosition.

%

%   Rendering Parameters:

%     'Color'     one of the strings 'bw', 'gray', 'cmyk'

%         'bw'    specifies that lines and text are exported in

%                 black and all other objects in grayscale

%         'gray'  specifies that all objects are exported in grayscale

%         'cmyk'  specifies that all objects are exported in color

%                 using the CMYK color space

%     'Renderer'  one of the strings 'painters', 'zbuffer', 'opengl'

%         specifies the renderer to use

%     'Resolution'   a positive scalar

%         specifies the resolution in dots-per-inch.

%

%     The default color setting is 'bw'.

%

%   Font Parameters:

%     'FontMode'     one of the strings 'scaled', 'fixed'

%     'FontSize'     a positive scalar

%          in 'scaled' mode multiplies with the font size of each

%          text object to obtain the exported font size

%          in 'fixed' mode specifies the font size of all text

%          objects in points

%     'FontEncoding' one of the strings 'latin1', 'adobe'

%          specifies the character encoding of the font

%

%     If FontMode is 'scaled' but FontSize is not specified then a

%     scaling factor is computed from the ratio of the size of the

%     exported figure to the size of the actual figure. The minimum

%     font size allowed after scaling is 5 points.

%     If FontMode is 'fixed' but FontSize is not specified then the

%     exported font sizes of all text objects is 7 points.

%

%     The default 'FontMode' setting is 'scaled'.

%

%   Line Width Parameters:

%     'LineMode'     one of the strings 'scaled', 'fixed'

%     'LineWidth'    a positive scalar

%          the semantics of LineMode and LineWidth are exactly the

%          same as FontMode and FontSize, except that they apply

%          to line widths instead of font sizes. The minumum line

%          width allowed after scaling is 0.5 points.

%          If LineMode is 'fixed' but LineWidth is not specified

%          then the exported line width of all line objects is 1

%          point.

%

%   Examples:

%     exportfig(gcf,'fig1.eps','height',3);

%       Exports the current figure to the file named 'fig1.eps' with

%       a height of 3 inches (assuming the figure's PaperUnits is

%       inches) and an aspect ratio the same as the figure's aspect

%       ratio on screen.

%

%     exportfig(gcf, 'fig2.eps', 'FontMode', 'fixed',...

%                'FontSize', 10, 'color', 'cmyk' );

%       Exports the current figure to 'fig2.eps' in color with all

%       text in 10 point fonts. The size of the exported figure is

%       the figure's PaperPostion width and height.

特别声明,这个程序不是我编的,我只是用了感觉很好,与大家分享。

转载本文请联系原作者获取授权,同时请注明本文来自雷锦志科学网博客。

链接地址:http://blog.sciencenet.cn/blog-267716-567996.html

上一篇:科研中的“拿来主义”要不得

下一篇:一篇令我感到为难的审稿(已更新)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值