Displaying Multiple Plots per Figure :: Basic Plotting Commands (Graphics) (2024)

GraphicsDisplaying Multiple Plots per Figure :: Basic Plotting Commands (Graphics) (1)Displaying Multiple Plots per Figure :: Basic Plotting Commands (Graphics) (2)

Displaying Multiple Plots per Figure

You can display multiple plots in the same figure window and print them on the same piece of paper with the subplot function.

subplot(m,n,i) breaks the figure window into an m-by-n matrix of small subplots and selects the ith subplot for the current plot. The plots are numbered along the top row of the figure window, then the second row, and so forth.

For example, the following statements plot data in four different subregions of the figure window.

  • t = 0:pi/20:2*pi;[x,y] = meshgrid(t);subplot(2,2,1)plot(sin(t),cos(t)) axis equalsubplot(2,2,2)z = sin(x)+cos(y);plot(t,z)axis([0 2*pi -2 2])subplot(2,2,3)z = sin(x).*cos(y);plot(t,z)axis([0 2*pi -1 1])subplot(2,2,4)z = (sin(x).^2)-(cos(y).^2);plot(t,z)axis([0 2*pi -1 1])

    Displaying Multiple Plots per Figure :: Basic Plotting Commands (Graphics) (3)

Each subregion contains its own axes with characteristics you can control independently of the other subregions. This example uses the axis command to set limits and change the shape of the subplots.

See the axes, axis, and subplot functions for more information.


Displaying Multiple Plots per Figure :: Basic Plotting Commands (Graphics) (4)Figure WindowsSpecifying the Target AxesDisplaying Multiple Plots per Figure :: Basic Plotting Commands (Graphics) (5)

© 1994-2005 The MathWorks, Inc.


Displaying Multiple Plots per Figure :: Basic Plotting Commands (Graphics) (2024)
Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 5644

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.