- 积分
- 1923
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2021-2-9
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 淘气包马小跳 于 2021-8-5 14:50 编辑
声明:这是一篇引用总结类帖子
目的:使MATLAB输出的图片美观,便于论文使用。 工具:MATLAB R2015b。
资料来源:参考CSDN论坛、气象家园。
方法一:适用于plot去除图片空白的RemovePlotWhiteArea.m。
(来源:此为CSDN博主「itsc」的原创文章,原文链接:https://blog.csdn.net/shanchuan2012/article/details/53980288)- <font face="楷体, 楷体_GB2312"><font face="楷体, 楷体_GB2312">% RemovePlotWhiteArea: 去除Plot画的图的空白部分
- % RemovePlotWhiteArea(gca)
- % 输入
- % gca: axes句柄
- % author : TSC
- % time : 2017-01-02
- % email :
- function [] = RemovePlotWhiteArea(gca)
- % TightInset的位置
- inset_vectior = get(gca, 'TightInset');
- inset_x = inset_vectior(1);
- inset_y = inset_vectior(2);
- inset_w = inset_vectior(3);
- inset_h = inset_vectior(4);
- % OuterPosition的位置
- outer_vector = get(gca, 'OuterPosition');
- pos_new_x = outer_vector(1) + inset_x; % 将Position的原点移到到TightInset的原点
- pos_new_y = outer_vector(2) + inset_y;
- pos_new_w = outer_vector(3) - inset_w - inset_x; % 重设Position的宽
- pos_new_h = outer_vector(4) - inset_h - inset_y; % 重设Position的高
- % 重设Position
- set(gca, 'Position', [pos_new_x, pos_new_y, pos_new_w, pos_new_h]);</font></font></font>
复制代码
方法二:适用于subplot去除图片空白的RemoveSubplotWhiteArea.m。
(来源:此为CSDN博主「itsc」的原创文章,原文链接:https://blog.csdn.net/shanchuan2012/article/details/53980288)
- % RemoveSubplotWhiteArea: 去除subplot周围的空白部分
- % RemoveSubplotWhiteArea(gca, sub_row, sub_col, current_row, current_col)
- % 输入
- % gca :axes句柄
- % sub_row :subplot的行数
- % sub_col :subplot的列数
- % current_row :当前列数
- % current_col :当前行数
- %
- % 注意:使用如下语句,print保存图片的时候使其按照设置来保存,否则修改无效
- % set(gcf, 'PaperPositionMode', 'auto');
- function [] = RemoveSubplotWhiteArea(gca, sub_row, sub_col, current_row, current_col)
- % 设置OuterPosition
- sub_axes_x = current_col*1/sub_col - 1/sub_col;
- sub_axes_y = 1-current_row*1/sub_row; % y是从上往下的
- sub_axes_w = 1/sub_col;
- sub_axes_h = 1/sub_row;
- set(gca, 'OuterPosition', [sub_axes_x, sub_axes_y, sub_axes_w, sub_axes_h]); % 重设OuterPosition
- % TightInset的位置
- inset_vectior = get(gca, 'TightInset');
- inset_x = inset_vectior(1);
- inset_y = inset_vectior(2);
- inset_w = inset_vectior(3);
- inset_h = inset_vectior(4);
- % OuterPosition的位置
- outer_vector = get(gca, 'OuterPosition');
- pos_new_x = outer_vector(1) + inset_x; % 将Position的原点移到到TightInset的原点
- pos_new_y = outer_vector(2) + inset_y;
- pos_new_w = outer_vector(3) - inset_w - inset_x; % 重设Position的宽
- pos_new_h = outer_vector(4) - inset_h - inset_y; % 重设Position的高
- % 重设Position
- set(gca, 'Position', [pos_new_x, pos_new_y, pos_new_w, pos_new_h]);
复制代码
方法三:自定义图片位置和大小的tight_subplot.m。
(来源:此为CSDN博主「五道口纳什」的原创文章,原文链接:https://blog.csdn.net/lanchunhui/article/details/49820721)
- <font face="楷体, 楷体_GB2312">
- <font face="楷体, 楷体_GB2312">function [ha, pos] = tight_subplot(Nh, Nw, gap, marg_h, marg_w)
- % tight_subplot creates "subplot" axes with adjustable gaps and margins
- %
- % [ha, pos] = tight_subplot(Nh, Nw, gap, marg_h, marg_w)
- %
- % in: Nh number of axes in hight (vertical direction)
- % Nw number of axes in width (horizontaldirection)
- % gap gaps between the axes in normalized units (0...1)
- % or [gap_h gap_w] for different gaps in height and width
- % marg_h margins in height in normalized units (0...1)
- % or [lower upper] for different lower and upper margins
- % marg_w margins in width in normalized units (0...1)
- % or [left right] for different left and right margins
- %
- % out: ha array of handles of the axes objects
- % starting from upper left corner, going row-wise as in
- % subplot
- % pos positions of the axes objects
- %
- % Example: ha = tight_subplot(3,2,[.01 .03],[.1 .01],[.01 .01])
- % for ii = 1:6; axes(ha(ii)); plot(randn(10,ii)); end
- % set(ha(1:4),'XTickLabel',''); set(ha,'YTickLabel','')
- % Pekka Kumpulainen 21.5.2012 @tut.fi
- % Tampere University of Technology / Automation Science and Engineering
- if nargin<3; gap = .02; end
- if nargin<4 || isempty(marg_h); marg_h = .05; end
- if nargin<5; marg_w = .05; end
- if numel(gap)==1;
- gap = [gap gap];
- end
- if numel(marg_w)==1;
- marg_w = [marg_w marg_w];
- end
- if numel(marg_h)==1;
- marg_h = [marg_h marg_h];
- end
- axh = (1-sum(marg_h)-(Nh-1)*gap(1))/Nh;
- axw = (1-sum(marg_w)-(Nw-1)*gap(2))/Nw;
- py = 1-marg_h(2)-axh;
- % ha = zeros(Nh*Nw,1);
- ii = 0;
- for ih = 1:Nh
- px = marg_w(1);
-
- for ix = 1:Nw
- ii = ii+1;
- ha(ii) = axes('Units','normalized', ...
- 'Position',[px py axw axh], ...
- 'XTickLabel','', ...
- 'YTickLabel','');
- px = px+axw+gap(2);
- end
- py = py-axh-gap(1);
- end
- if nargout > 1
- pos = get(ha,'Position');
- end
- ha = ha(:);</font>
- </font>
复制代码
简单说明:
tight_subplot(Nh, Nw, gap, marg_h, marg_w)
我们先来介绍参数的含义:Nh, Nw用法同subplot(row, col)表示行数和列数,gap(如[0.01, 0.1])表示子图之间垂直方向和水平方向的间隔,marg_h表示的是全部子图到figure上下边界的距离,marg_w则表示的是全部子图到figure左右边界的距离。
下面给出三个m文件:
tight_subplot.m
(2.03 KB, 下载次数: 8)
|
-
方法三图片示例
评分
-
查看全部评分
|