找回密码
 注册
Simdroid-非首页
查看: 131|回复: 7

图片坐标被盖住的调整方法

[复制链接]
发表于 2011-1-10 21:27:22 | 显示全部楼层 |阅读模式 来自 江苏南京
整了个双y轴的图片,
结果用position控制图片大小时,
很多的坐标标签被盖住了,
不知如何在m文件中通过命令调整,
在网上收了很久都没搞定。
谢谢指点了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
发表于 2011-1-11 18:59:43 | 显示全部楼层 来自 黑龙江哈尔滨
Simdroid开发平台
没遇到过这种情况,你最好把代码贴出来。
回复 不支持

使用道具 举报

 楼主| 发表于 2011-1-12 16:57:21 | 显示全部楼层 来自 江苏南京
首先感谢big boss的回复啊:lol

代码如下附件。

一方面,坐标标识被盖住
另一方面,如何设置两个的Y坐标数值的比例为1:1,即下图中的sin应该比2×cos小些。
谢谢big boss了。


clc;
clear all;
x=[0:0.1:10];
y1=sin(x);
y2=2*cos(x);
figbar=figure(1)
    tmp=transpose(x);
    [ax,h1,h2]=plotyy(x,y1,tmp,y2,'plot');
    set(get(ax(1),'Ylabel'),'string','y1','color','k','fontsize',14)
    set(get(ax(2),'Ylabel'),'string','y2','color','k','fontsize',14)   
    xlabel('Distance','fontsize',14)
    set(h1,'linestyle','-','color','b','LineWidth',2);
    set(h2,'linestyle','--','color','r','LineWidth',2);
    legend([h1 h2],'sin(x)','2*cos(x)','fontsize',14) %标注两条线
    legend('boxoff')
    set(figbar,'Position',[200,200,400,400]);
    set(ax,'fontsize',14) % 设置x轴范围

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

发表于 2011-1-12 21:04:23 | 显示全部楼层 来自 北京
本帖最后由 ljelly 于 2011-1-12 21:15 编辑
首先感谢big boss的回复啊:lol

代码如下附件。

一方面,坐标标识被盖住
另一方面,如何设置两个的Y坐标数值的比例为1:1,即下图中的sin应该比2×cos小些。
谢谢big boss了。


clc;
clear all;
x=[0:0. ...
jacobi 发表于 2011-1-12 16:57

问题1,坐标标识被盖住,是因为你的图设置的太小,设置大一点就ok了
问题2,通过调整轴属性是可以改变的
调整后的代码如下,图如下所示
  1. clc;
  2. clear all;
  3. x=0:0.1:12;
  4. y1=sin(x);
  5. y2=2*cos(x);
  6. figbar=figure(1);
  7. tmp=transpose(x);
  8. [ax,h1,h2]=plotyy(x,y1,tmp,y2,'plot');
  9. set(get(ax(1),'Ylabel'),'string','y1','color','k','fontsize',14)
  10. set(get(ax(2),'Ylabel'),'string','y2','color','k','fontsize',14)
  11. xlabel('Distance','fontsize',14)
  12. set(h1,'linestyle','-','color','b','LineWidth',2);
  13. set(h2,'linestyle','--','color','r','LineWidth',2);
  14. legend([h1 h2],'sin(x)','2*cos(x)','fontsize',14) %标注两条线
  15. legend('boxoff')
  16. set(figbar,'Position',[200,200,600,500]);
  17. set(ax,'fontsize',14) ;
  18. set(ax(1),'ylim',[-2 2],'ytick',[-2 -1 0 1 2])
  19. set(ax(1),'ylim',[-2 2],'ytick',-2:0.5:2)
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2011-1-13 08:42:03 | 显示全部楼层 来自 江苏南京
首先,非常感谢ljelly 兄的回复。
其次,一个小问题求教一下{:3_54:}
一般我绘图大小都用---[400,100,400,350]的大小,图中字体都是fontsize14,
这样出来的图放到WORD中后,设置比例为60%的话,图中字体显示差不多和小五字体大小接近。
以前一直是这样的比例。

现在弄的那个双Y轴后,图片大小设置为[200,200,600,500]后,坐标标签虽然显示出来了,
但是此时字体设置的是14,显然相对上述的比例,字体显得小了,
于是增大字体,问题是字体是增大了,但是这时图片的[200,200,600,500]又小了,
又要增大[200,200,600,500],如此反复,比较头疼,


感觉很奇怪,这个[200,200,600,500]大小是调整整个图片大小的,
而不是调整坐标轴所框住的面积,通过增大整个图面的方法来显示字体的方法难以凑效,

在matlab中找了很久,
在里面找到以下说明,
似乎应该可以达到效果。
实践证明,同时给定position和outerposition还是解决不了问题。
由于对matlab的图柄操作不熟,所以没有深究了,
还望高人能给点力{:3_54:}



Automatic Axes Resize
On this page…
Properties Controlling Axes Size
Using OuterPosition as the ActivePositionProperty
ActivePositionProperty = OuterPosition
ActivePositionProperty = Position
Axes Resizing in Subplots
Properties Controlling Axes Size
When you create a graph, the MATLAB? software automatically creates an axes to display the graph. The axes is sized to fit in the figure and automatically resizes as you resize the figure. Note, however, that MATLAB applies the automatic resize behavior only when the axes Units property is set to normalized (the default).
You can control the resize behavior of the axes using the following axes properties.
    *
      OuterPosition — The boundary of the axes including the axis labels, title, and a margin. For figures with only one axes, this is the interior of the figure.
    *
      Position — The boundary of the axes, excluding the tick marks and labels, title, and axis labels.
    *
      ActivePositionProperty — Specifies whether to use the OuterPosition or the Position property as the size to preserve when resizing the figure containing the axes.
    *
      TightInset — The margins added to the width and height of the Position property to include text labels, title, and axis labels.
    *
      Units — Keep this property set to normalized to enable automatic axes resizing.
The following graph shows the areas defined by the OuterPosition, TightInset + Position, and Position properties.
When you add axis labels and a title, the TightInset changes to accommodate the additional text, as shown in the following graph.
Now the size of the rectangle defined by the TightInset + Position properties includes all graph text. The Position and OuterPosition properties remain unchanged.
Back to Top of Page Back to Top
Using OuterPosition as the ActivePositionProperty
As you resize the figure, MATLAB maintains the area defined by the TightInset + Position so the text is not cut off. Compare the next two graphs, which have both been resized to the same figure size.
Back to Top of Page Back to Top
ActivePositionProperty = OuterPosition
Back to Top of Page Back to Top
ActivePositionProperty = Position
The following picture shows how these properties apply to 3-D graphs.
Back to Top of Page Back to Top
Axes Resizing in Subplots
Using the OuterPosition property as the ActivePositionProperty is an effective way to prevent titles and labels from being overwritten when there are multiple axes in a figure.
The following picture illustrates how MATLAB resizes the axes to accommodate the multiline titles on the lower two axes.
The default 3-D view is azimuth = -37.5°, elevation = 30°.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

发表于 2011-1-13 10:09:54 | 显示全部楼层 来自 重庆沙坪坝区
学习了 多谢多谢额

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2011-1-13 17:23:32 | 显示全部楼层 来自 北京
5# jacobi
你再控制一下轴的位置,还按照你原来图形的大小
是可以做到的
回复 不支持

使用道具 举报

发表于 2011-1-13 21:22:02 | 显示全部楼层 来自 天津
[fs,map]=getframe(gcf);
imwrite(fs,imageName,'Compression','none');      
其中gcf为图形句柄.
建议楼主使用这两步来自动存储图象,因为这样的图象是所见所得的,没有"变形".
之前很多人专门讨论如何编写复杂程序来保存fig上的图(无畸变),其实就可以按上面那么最简单地去做,而且效果挺好.

评分

1

查看全部评分

回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-5 03:24 , Processed in 0.043788 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表