zoukankan      html  css  js  c++  java
  • MATLAB画图之多子图画法(subplot和自己确定大小位置两种方法)

    解决问题:在一个图中画多个子图,又能自己确定子图的大小和位置。

    解决方法:有两种解决方法可以实现:

    1. 使用subplot命令
    2. 使用axes函数来重新规定子图的大小和位置。

    这两种方法中,第一种方法相对简单,但是第二种方法更加灵活,具体使用如下:

    第一种方法:使用subplot

    先看一下subplot的简单使用,程序如下:

    clear;
    clc;
    close all;
    t = 0:0.001:10;
    y1 = sin(t);
    y2 = cos(t);
    
    figure (1);
    subplot(2,2,1)
    plot(t,y1);
    subplot(2,2,2)
    plot(t,y1);
    subplot(2,2,3)
    plot(t,y2);
    subplot(2,2,4)
    plot(t,y2);

    程序运行结果:

    使用subplot的这种方法,如果想要自定义子图的大小和位置该怎么设置?

    程序如下:

    clear;
    clc;
    close all;
    t = 0:0.001:10;
    y1 = sin(t);
    y2 = cos(t);
     
    figure(1);
    subplot('position',[0.2,0.7,0.6,0.2]);
    plot(t,y1);
    subplot('position',[0.2,0.2,0.6,0.2]);
    plot(t,y2);
    

    程序运行结果:

    第二种方法:直接使用axes函数

    程序如下:

    clear;
    clc;
    close all;
    t = 0:0.001:10;
    y1 = sin(t);
    y2 = cos(t);
    
    figure (1);
    axes('position',[0.1 0.6 0.3 0.3]);
    plot(t,y1);
    axes('position',[0.6 0.6 0.3 0.3]);
    plot(t,y1);
    axes('position',[0.1 0.1 0.3 0.3]);
    plot(t,y2);
    axes('position',[0.6 0.1 0.3 0.3]);
    plot(t,y2);

    程序运行结果:

     其中,'position',[0.6 0.1 0.3 0.3]的含义可以参考我之前的博客文章,有详细说明;

    如果要自定义整个figure的大小,设置gcf,我之前的博客文章也有详细说明。

  • 相关阅读:
    Python模糊查询本地文件夹去除文件后缀(7行代码)
    Python正则表达式
    python的logging模块
    Python中hashlib模块
    Python的os模块
    项目初始化mysql建库和授权
    Add correct host key in /root/.ssh/known_hosts to get rid of this message
    高中典型的等比数学题
    autoenv的使用方法
    celery任务进程关闭
  • 原文地址:https://www.cnblogs.com/pupilLZT/p/12542691.html
Copyright © 2011-2022 走看看