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

【分享】三轴绘图程序

[复制链接]
发表于 2005-12-16 13:00:29 | 显示全部楼层 |阅读模式 来自 新疆乌鲁木齐
上次见到有人问怎么画三轴图形,印象中最后好像没结果了,今天碰巧在files exchange看到这个程序,搜索功能现在不好使,只有发新贴了,希望对这位朋友还有用。
function [ax,hlines] = plotyyy(x1,y1,x2,y2,x3,y3,ylabels)
%PLOTYYY - Extends plotyy to include a third y-axis
%
%Syntax:  [ax,hlines] = plotyyy(x1,y1,x2,y2,x3,y3,ylabels)
%
%Inputs: x1,y1 are the xdata and ydata for the first axes' line
%        x2,y2 are the xdata and ydata for the second axes' line
%        x3,y3 are the xdata and ydata for the third axes' line
%        ylabels is a 3x1 cell array containing the ylabel strings
%
%Outputs: ax -     3x1 double array containing the axes' handles
%         hlines - 3x1 double array containing the lines' handles

%Author: Denis Gilbert, Ph.D., physical oceanography
%Maurice Lamontagne Institute
%Dept. of Fisheries and Oceans Canada
%email: gilbertd@dfo-mpo.gc.ca  
%Web: http://www.qc.dfo-mpo.gc.ca/iml/
%April 2000; Last revision: 14-Nov-2001

if nargin==6
   ylabels{1}=' '; ylabels{2}=' '; ylabels{3}=' ';
elseif nargin > 7
   error('Too many input arguments')
elseif nargin < 6
   error('Not enough input arguments')
end

figure('units','normalized',...
       'DefaultAxesXMinorTick','on','DefaultAxesYminorTick','on');

[ax,hlines(1),hlines(2)] = plotyy(x1,y1,x2,y2);
cfig = get(gcf,'color');
pos = [0.1  0.1  0.7  0.8];
offset = pos(3)/5.5;

pos(3) = pos(3) - offset/2;
set(ax,'position',pos);  

pos3=[pos(1) pos(2) pos(3)+offset pos(4)];

limx1=get(ax(1),'xlim');
limx3=[limx1(1)   limx1(1) + 1.2*(limx1(2)-limx1(1))];

ax(3)=axes('Position',pos3,'box','off',...
   'Color','none','XColor','k','YColor','r',...   
   'xtick',[],'xlim',limx3,'yaxislocation','right');

hlines(3) = line(x3,y3,'Color','r','Parent',ax(3));
limy3=get(ax(3),'YLim');

line([limx1(2) limx3(2)],[limy3(1) limy3(1)],...
   'Color',cfig,'Parent',ax(3),'Clipping','off');
axes(ax(2))

set(get(ax(1),'ylabel'),'string',ylabels{1})
set(get(ax(2),'ylabel'),'string',ylabels{2})
set(get(ax(3),'ylabel'),'string',ylabels{3})

example:
x=0:10;
y1=x;  y2=x.^2;   y3=x.^3;
ylabels{1}='First y-label';
ylabels{2}='Second y-label';
ylabels{3}='Third y-label';
[ax,hlines] = plotyyy(x,y1,x,y2,x,y3,ylabels);
legend(hlines, 'y = x','y = x^2','y = x^3',2)

figure shown as below:

本帖子中包含更多资源

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

×

评分

1

查看全部评分

发表于 2006-3-7 14:39:39 | 显示全部楼层 来自 山东青岛

Re:【分享】三轴绘图程序

Simdroid开发平台
请问:
这句
line([limx1(2) limx3(2)],[limy3(1) limy3(1)],...
'Color',cfig,'Parent',ax(3),'Clipping','off');

作用是裁剪掉比plotyy横坐标多出来的那段坐标轴吧?
那么'Clipping','on'时又有什么作用?
我怎么自己画图时试不出来?(想剪掉一段直线而未果)
究竟怎样才是裁剪?
例如:
>> x=1:1:5;
>> y=x;
>> plot(x,y)
>> cfig=get(gcf,'color')
>> line([1 3],[1 3],'Color',cfig,'clipping','off')%本意是想剪掉x=1:3这段;结果好像变成虚线了。怎样才能定义成无色?或真正剪掉?
 楼主| 发表于 2006-3-10 16:58:17 | 显示全部楼层 来自 新疆乌鲁木齐

Re:【分享】三轴绘图程序

其实早已经看到这个问题,一直抽不出时间做,今天正好得空儿,写一个程序说明一下,你所说的clipping其实不叫“裁剪”而是自适应于axes或者figure的长度,所谓裁剪是根本就没有了,下面这个程序则可看出您的理解是错误的——线仍然存在,图形裁剪用nan赋值即可:
  1. function ClippingProterty
  2. clc
  3. close all
  4. x=-5:15;
  5. hFig1=figure;
  6. subplot(221)
  7. LineHandles=plot(x,x+5,'--r',x,x-3,'g');
  8. TextHandles(1)=text(6.5,5,...
  9.     'This String will have clipping off');
  10. TextHandles(2)=text(-1,3.5,...
  11.     'This String will have clipping off too');
  12. axis([0 10 0 10]);
  13. subplot(222)
  14. LineHandles=plot(x,x+5,'--r',x,x-3,'g');
  15. set(LineHandles(1),'clipping','off')
  16. TextHandles(1)=text(6.5,5,...
  17.     'This String will have clipping on');
  18. TextHandles(2)=text(-1,3.5,...
  19.     'This String will have still been clipping off');
  20. axis([0 10 0 10]);
  21. subplot(223)
  22. LineHandles=plot(x,x+5,'--r',x,x-3,'g');
  23. hSubLine1=findobj(LineHandles,'color','r');
  24. set(hSubLine1,'linewidth',2.5)
  25. subplot(224)
  26. y1=x+5;
  27. x([4:11])=NaN;
  28. LineHandles=plot(x,y1,'--r',[-5:15],[-5:15]-3,'g');
  29. hSubLine1=findobj(LineHandles,'color','r');
  30. set(hSubLine1,'linewidth',2.5)
复制代码

本帖子中包含更多资源

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

×
发表于 2006-3-10 20:21:17 | 显示全部楼层 来自 新加坡

Re:【分享】三轴绘图程序

谢谢bainhome的推荐和解释!
发表于 2006-3-13 09:01:31 | 显示全部楼层 来自 山东青岛

Re:【分享】三轴绘图程序

明白了,谢谢!
liangkunf 该用户已被删除
发表于 2006-4-1 19:35:03 | 显示全部楼层 来自 江苏南京
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2010-9-15 15:55:03 | 显示全部楼层 来自 江苏南京
看看上楼的

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2010-9-15 23:20:23 | 显示全部楼层 来自 黑龙江哈尔滨
谢谢了,很好用

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2011-9-9 09:07:59 | 显示全部楼层 来自 河南郑州
看看都要积分
回复 不支持

使用道具 举报

发表于 2012-2-29 16:42:44 | 显示全部楼层 来自 江西宜春
在软件上试了下,不行,出了错误。??? function [ax,hlines] = plotyyy(x1,y1,x2,y2,x3,y3,ylabels)
    |
Error: Function definitions are not permitted in this context.
回复 不支持

使用道具 举报

发表于 2012-3-21 19:53:48 | 显示全部楼层 来自 黑龙江哈尔滨
楼主辛苦啦!!

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2012-6-23 17:57:45 | 显示全部楼层 来自 上海
谢谢啊
回复 不支持

使用道具 举报

发表于 2012-6-24 16:25:36 | 显示全部楼层 来自 重庆沙坪坝区
学习!收藏了,在其他论坛上好像看到过plot4y的函数
回复 不支持

使用道具 举报

发表于 2012-7-3 22:02:26 | 显示全部楼层 来自 山东济南
:o:o好的,谢谢
回复 不支持

使用道具 举报

发表于 2012-8-17 19:43:14 | 显示全部楼层 来自 北京
多谢楼主分享资料
回复 不支持

使用道具 举报

发表于 2013-12-7 02:09:26 | 显示全部楼层 来自 江苏南京
好东西,学习了,三轴图表示多个变量看着就是舒服。
回复 不支持

使用道具 举报

发表于 2014-4-1 18:29:41 | 显示全部楼层 来自 辽宁沈阳
唉!大神们,我们连三轴图是什么都不知道,差的太多了
回复 不支持

使用道具 举报

发表于 2014-4-16 10:01:07 | 显示全部楼层 来自 山东青岛
收藏了,感谢楼主分享:)
回复 不支持

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-16 22:08 , Processed in 0.067722 second(s), 21 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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