How Do You Make All the Axes the Same in Matlab When Using Subplots?

Written by thomas bourdin
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How Do You Make All the Axes the Same in Matlab When Using Subplots?
MATLAB can be used to simulate many different engineering problems to ensure the proper design. ( Images)

MATLAB is a computer environment created by computer scientist Cleve Moler and is used for numerical computing and creating high-level computer programs. MATLAB is commonly used in scientific and engineering applications because of it's simple-to-learn language syntax and computational power. A common task when using MATLAB is creating many similar plots simultaneously. This may require that the plots all have the same axes so that the plots can be easily compared. This can be done in MATLAB using a function called 'linkaxes'. Using this command within MATLAB can be understood with some knowledge of the MATLAB environment.

Skill level:

Other People Are Reading

Things you need

  • Computer with MATLAB software installed

Show MoreHide


  1. 1

    Allocate the subplot you would like to create. For example, if you are creating two plots with one located vertically above the other, type the command

    > axe(1) = subplot(2,1,1)

    The first number represents the number of vertical plots, the second number represents the number of horizontal plots and the third number represents the index of the current plot.

  2. 2

    Create the individual plot within the subplot. This can be done using the command

    >plot(x,y, axe(1) )

    where x is the data on the horizontal axis, y is the data on the vertical axis and axe(1) is the subplot to plot the data onto.

  3. 3

    Repeat the steps above to create the second subplot. For example, this can be created using the commands

    > axe(2) = subplot(2,1,2)

    >plot(x,y, axe(2) )

    and where the data x,y does not have to be the same values, or size as the first set of data.

  4. 4

    Link the different subplots using the 'linkaxes' command. For example, the command

    >linkaxes( axe, 'x');

    will link the x-axes of the two plots, so if you zoom into an area of one of the plots, both plots will automatically zoom into this region. To link the y-axes, replace 'x' with 'y', and to link both axes, type 'xy' instead.

Tips and warnings

  • Use the MATLAB documentation to understand how to use specific related commands such as 'plot', 'size', 'subplot', and 'linkaxes'.
  • Ensure you do not use any predefined commands in MATLAB to name variables or plots. For example, the command 'plot' is already reserved, so naming your graphs 'plot' may create problems in MATLAB.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.