QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1835|回复: 3
打印 上一主题 下一主题

[我分享] 四个坐标轴绘图函数

[复制链接]
字体大小: 正常 放大

2329

主题

34

听众

6297

积分

  • TA的每日心情

    2013-11-18 14:37
  • 签到天数: 76 天

    [LV.6]常住居民II

    自我介绍
    阳光

    群组2013年数学建模国赛备

    群组2013年国赛A题讨论组

    群组2013年国赛B题讨论组

    群组2013年国赛C题讨论组

    群组2013年国赛D题讨论组

    跳转到指定楼层
    1#
    发表于 2013-8-10 10:41 |只看该作者 |倒序浏览
    |招呼Ta 关注Ta
    210847fqpivmmdmzdkgx4x.jpg
    发现一个画四个坐标轴的绘图函数,不敢独享~
    function [ax,hlines] = ploty4(x1,y1,x2,y2,x3,y3,x4,y4,ylabels)
    %PLOTY4 Extends plotyy to include a third and fourth y-axis
    %
    % Syntax: [ax,hlines] = ploty4(x1,y1,x2,y2,x3,y3,x4,y4,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
    % x4,y4 are the xdata and ydata for the fourth axes' line
    % ylabels is a 4x1 cell array containing the ylabel strings (optional)
    %
    % Outputs: ax - 4x1 double array containing the axes' handles
    % hlines - 4x1 double array containing the lines' handles
    %
    % Example:
    % x = 0:10;
    % y1=x; y2=x.^2; y3=x.^3; y4=x.^4;
    % ylabels{1} = 'First y-label';
    % ylabels{2} = 'Second y-label';
    % ylabels{3} = 'Third y-label';
    % ylabels{4} = 'Fourth y-label';
    % [ax,hlines] = ploty4(x,y1,x,y2,x,y3,x,y4,ylabels);
    % leghandle = legend(hlines, 'y = x','y = x^2','y = x^3','y = x^4',2);
    %
    % See also Plot, Plotyy

    % Denis Gilbert, Ph.D.


    % Check inputs
    msg=nargchk(8,9,nargin);
    error(msg);

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

    %Plot the first two lines with plotyy
    [ax,hlines(1),hlines(2)] = plotyy(x1,y1,x2,y2);
    cfig = get(gcf,'color');
    pos = [0.125 0.1 0.65 0.8];
    offset = pos(3)/5.5;

    %Reduce width of the two axes generated by plotyy
    pos(1) = pos(1) + offset;
    pos(3) = pos(3) - offset;
    set(ax,'position',pos);

    %Determine the position of the third/fourth axes
    pos3 = [pos(1) pos(2) pos(3)+offset pos(4)];
    pos4 = [pos(1) - offset pos(2) pos(3)+offset pos(4)];

    %Determine the proper x-limits for the third and fourth axes
    scale3 = pos3(3)/pos(3);
    scale4 = pos4(3)/pos(3);
    limx1 = get(ax(1),'xlim');
    limx3 = [limx1(1) limx1(1)+scale3*(limx1(2)-limx1(1))];
    limx4 = [limx1(2)-scale4*(limx1(2)-limx1(1)) limx1(2)];

    %Create ax(3) & ax(4)
    ax(3) = axes('Position',pos3,'box','off',...
    'Color','none','XColor',cfig,'YColor','r',...
    'xtick',[],'xlim',limx3,'yaxislocation','right');
    ax(4) = axes('Position',pos4,'box','off',...
    'Color','none','XColor',cfig,'YColor','k',...
    'xtick',[],'xlim',limx4,'yaxislocation','left');

    %Plot x3,y3,x4,y4
    hlines(3) = line(x3,y3,'Color','r','Parent',ax(3));
    hlines(4) = line(x4,y4,'Color','k','Parent',ax(4));

    %Put ax(2) on top;
    axes(ax(2));

    %Set y-labels;
    if nargin==9
    set(cell2mat(get(ax,{'ylabel'})),{'String'},{ylabels{:}}');
    end
    这是一个测试代码:
    x = 0:10;
    y1=x; y2=x.^2; y3=x.^3; y4=x.^4;
    ylabels{1} = 'First y-label';
    ylabels{2} = 'Second y-label';
    ylabels{3} = 'Third y-label';
    ylabels{4} = 'Fourth y-label';
    [ax,hlines] = ploty4(x,y1,x,y2,x,y3,x,y4,ylabels);
    leghandle = legend(hlines, 'y = x','y = x^2','y = x^3','y = x^4',2);
    zan
    转播转播 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
    mathsky55        

    32

    主题

    7

    听众

    389

    积分

    升级  29.67%

  • TA的每日心情
    奋斗
    2014-9-15 00:54
  • 签到天数: 26 天

    [LV.4]偶尔看看III

    自我介绍
    大一新生

    新人进步奖

    群组数学建模培训课堂1

    群组Matlab讨论组

    群组数学建摸协会

    群组第三届数模基础实训

    群组各种优秀论文集锦

    回复

    使用道具 举报

    阔远        

    1

    主题

    9

    听众

    115

    积分

    升级  7.5%

  • TA的每日心情

    2014-10-1 03:58
  • 签到天数: 38 天

    [LV.5]常住居民I

    自我介绍
    虽然刚刚上大学不久,但是自认为在学习还是比较努力,这学期会全力参加各项竞赛,争取拿到好名次!

    群组Matlab讨论组

    群组2013电工杯A题讨论群组

    群组高数系列公益培训

    群组数学建摸协会

    群组国赛讨论

    回复

    使用道具 举报

    59

    主题

    18

    听众

    836

    积分

    升级  59%

  • TA的每日心情
    无聊
    2016-1-24 14:24
  • 签到天数: 157 天

    [LV.7]常住居民III

    自我介绍
    没有最好,只有更好!

    新人进步奖

    群组建模思维养成培训

    群组数模专题强化培训

    回复

    使用道具 举报

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

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2025-5-9 00:25 , Processed in 0.897804 second(s), 75 queries .

    回顶部