14.5: Subplots

Matlab and Octave Programming for STEM Applications · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    14.5: Subplots

    The subplot() function allows you to place more than 1 plot within a single figure.

    These examples show its use. More information can be obtained by using "help subplot"

    Example \(\PageIndex{1}\) subplot() with 2 rows & 1 column

    %% 2 Subplots
    figure
    subplot(2,1,1);
    x = 0 : 0.1 : 13;
    y1 = sin(x);
    plot(x,y1)
    grid on;

    subplot(2,1,2);
    y2 = cos(x);
    plot(x,y2)
    grid on;

    Solution

    subplot_2functions.png

    .

     Example \(\PageIndex{2}\)subplot() with 3 rows & 2 columns

    %% 3x2 Subplots
    figure
    subplot(3,2,1);
    x = 0 : 0.1 : 13;
    ys1 = sin(x);
    plot(x,ys1)
    grid on;

    subplot(3,2,3);
    x = 0 : 0.1 : 13;
    ys2 = sin(2*x);
    plot(x,ys2)
    grid on;

    subplot(3,2,5);
    x = 0 : 0.1 : 13;
    ys3 = sin(3*x);
    plot(x,ys3)
    grid on;

    subplot(3,2,2);
    yc1 = cos(x);
    plot(x,yc1)
    grid on;

    subplot(3,2,4);
    yc2 = cos(2*x);
    plot(x,yc2)
    grid on;

    subplot(3,2,6);
    yc3 = cos(3*x);
    plot(x,yc3)
    grid on;

    Solution

    subplot32.png

    .

     


    This page titled 14.5: Subplots was last modified on Sun, 04 Aug 2024 22:06:50 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Carey Smith.