How to Plot Multiple Graphs on a Single Graph in Matlab

Written by thomas bourdin
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Plot Multiple Graphs on a Single Graph in Matlab
Plotting multiple graphs within a single graph can provide an easy way to compare results. (Hemera Technologies/ Images)

Matlab is a computing environment created by the software company Mathworks. It is commonly used in many scientific and engineering applications due to its numerical computing and programming functions. One task that is important for these types of applications are plots and graphs, which can be used to understand and illuminate the results of a specific program within Matlab. Placing multiple graphs within a single graph is one way to compare different results in Matlab. This is done using the "subplot" function.

Skill level:

Things you need

  • Computer running Matlab software

Show MoreHide


  1. 1

    Create, import or initialise the data that you will be plotting. For example, the commands below create a data set that will eventually be used for the horizontal axis "x", and three sets of data used for the vertical axis "y.'

    > x = [1 2 3 4 5];

    > y = [2 5 8 2 1; 4 8 11 5 5; 5 9 10 0 4 ];

  2. 2

    Use the subplot command to allocate space to place the multiple graphs. The command > subplot(3,1,1) "calls" the first subplot, allowing you to plot the data within that first plot. The first number in the subplot command indicates that there are three plots, placed vertically on top of each other; the second number indicates there is only one column of plots, and the third number indicates that the plot on the top is the one to focus on. Alternatively, the command >subplot(2,2,1) would indicate a 2 x 2 square of 4 different plots

  3. 3

    Plot the data within the subplot. The command >plot(x,y(1,:) ) will plot the first row of data on the first plot.

  4. 4

    Repeat the above commands to plot the remaining two graphs. In this example, these commands would be:


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


    >plot(x,y(3,:) ).

    There should now be three different graphs all plotted on top of one another on the same graph.

Tips and warnings

  • Use the Matlab documentation to study the correct usage of different commands, such as "plot and "subplot," and to understand how to initialise matrices 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.