Matlab图形窗口大小的控制 ,plot窗口大小,figure大小,axis设置

转载地址:http://blog.sina.com.cn/s/blog_48c735630101iadu.html

Matlab中保存图像时,图形窗口大小的控制zz

首先要了解的是Matlab是面向对象的。最高等级的对象是screen,它定义了figure可以用的最大szie。
screen下面是figure。figue就是你画图的时候跳出来的那个新的对话窗口。如果figure变化,screen是不会跟着变化的。但screen变化的话,figure就要跟着变化了。

figure下面是axes。axes是那个窗口里面你要画的东西。axes的大小和位置取决于figure,如果你放大缩小figure的大小的话,里面的图线也会跟着变化的。
set(gca,’position’,[])
因此,set (gca,’position’,[0.1,0.1,0.9,0.9] );的作用是:
设置坐标轴距离画板(图形窗口figure)边距。
[0.1,0.1,0.9,0.9] 分别为axes在figure中的左边界,下边界,宽度,高度,最小为0,最大为1(左边界,下边界为0,上边界,右边界为1)

见下面的例子:

figure
set (gca,’position’,[0.1,0.1,0.9,0.9] );
x=1:0.1:10;
y=sin(x);

plot(x,y)

结果见下图:
Matlab图形窗口大小的控制 ,plot窗口大小,figure大小,axis设置,实用
set(gcf,’position’,[])
一般matlab绘出来图的框架(图形窗口)大都是正方形或者近似正方形的矩形,能不能画一些扁的矩形呢?
使用图形的position属性可以做到。
如set(gcf,’unit’,’normalized’,’position’,[0.2,0.2,0.64,0.32]);的意思是:
对gcf的position进行设置。使其在屏幕上的显示位置是以(0.2,0.2)为原点,长0.64,宽0.32。同gca一样,仍然是左边界,下边界为0,
上边界,右边界为1。

另外,gcf的position也可以不是normalized的。如下面的例子:

x=-2*pi:0.1:2*9i;y=sin(x);figure;set (gcf,’Position’,[500,500,500,500], ‘color’,’w’) %大小设置plot(x,y,’k-‘) %节点位移图形输出xlim([min(s(:,2)) max(s(:,2))])grid on

其中,
[500,500,500,500]的意思为:原点的位置x,原点的位置y,宽,高,其坐标为points(详见下面),

现在问题还存在:
如果仅设置position的话,打印的时候还是正方形。可以用下面的方法解决:
通常默认情况下,print命令输出图像为 8*5inches,无视屏幕显示尺寸
通过命令行修改的话有三步
1 设置paperposition为manual
set(gcf,’PaperPositionMode’, ‘manual’)
[ auto | {manual} ]
2 设置paperunit
set(gcf,’PaperUnits’,’inches’)
[ {inches} | centimeters | normalized | points ]
3 设置paperposition
set(gcf,’PaperPosition’,[left,bottom,width,height])
例如
set(gcf, ‘PaperPositionMode’, ‘manual’);
set(gcf, ‘PaperUnits’, ‘points’);
set(gcf, ‘PaperPosition’, [0 0 640 480]);

还有一个相关命令是papersize
paperposition 是placement,代表图像在paper(感觉就是屏幕screen的意思?)中的所处位置。left和bottom计算好,就可以使图像在paper中居中
papersize是纸张大小;position要比size小的

PaperPosition
four-element rect vector
Location on printed page. A rectangle that determines the location of the figure on the printed page. Specify this rectangle with a vector of the form
rect = [left, bottom, width, height]
where left specifies the distance from the left side of the paper to the left side of the rectangle and bottom specifies the distance from the bottom of the page to the bottom of the rectangle. Together these distances define the lower-left corner of the rectangle. width and height define the dimensions of the rectangle. The PaperUnits property specifies the units used to define this rectangle.

要使图像比例输出与屏幕显示的一致,可以使用如下命令
屏幕显示图像尺寸可以plot时用 set(gcf,’position’,[left bottom width height]) 调整,或者print之前拖动窗口手动调整
This example exports a figure at screen size to a 24-bit TIFF file, myfigure.tif.

% set(gcf,’position’,[80 100 800 600]) % 如果手动拖放,则不需要这一行命令
set(gcf, ‘PaperPositionMode’, ‘auto’) % Use screen size
print -dtiff myfigure

用matlab画了一张图,投稿时要缩小,缩小后字体就会过小或者发虚。我摸索出比较好的方法是如下的代码:%%%%%%%%%%%%%%%%%%%%%%plot your figure before%%%%%%%%%%%%%%%%%%%%%% figure resize
set(gcf,’Position’,[100 100 260 220]);
set(gca,’Position’,[.13 .17 .80 .74]);
figure_FontSize=8;
set(get(gca,’XLabel’),’FontSize’,figure_FontSize,’Vertical’,’top’);
set(get(gca,’YLabel’),’FontSize’,figure_FontSize,’Vertical’,’middle’);
set(findobj(‘FontSize’,10),’FontSize’,figure_FontSize);
set(findobj(get(gca,’Children’),’LineWidth’,0.5),’LineWidth’,2);%%%%%%%%%%%%%%%%%%%%%%%%%%%%解释:set(gcf,’Position’,[100 100 260 220]);
这句是设置绘图的大小,不需要到word里再调整大小。我给的参数,图的大小是7cmset(gca,’Position’,[.13 .17 .80 .74]);
这句是设置xy轴在图片中占的比例,可能需要自己微调。figure_FontSize=8;
set(get(gca,’XLabel’),’FontSize’,figure_FontSize,’Vertical’,’top’);
set(get(gca,’YLabel’),’FontSize’,figure_FontSize,’Vertical’,’middle’);
set(findobj(‘FontSize’,10),’FontSize’,figure_FontSize);这4句是将字体大小改为8号字,在小图里很清晰set(findobj(get(gca,’Children’),’LineWidth’,0.5),’LineWidth’,2);
这句是将线宽改为2

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值