2 Plots 1 Figure Matlab

  • I'm new to MatLab (so please excuse my language) and am attempting to overlay two line plots of vectors, as coded here (actual vectors a and b are 50 elements long): a = 1, 2, 3 b = 1, 3, 2.
  • Create a figure containing with three subplots. Create two subplots across the upper half of the figure and a third subplot that spans the lower half of the figure. Add titles to each subplot.
  • Examples of Matlab Plot Multiple Lines. Given below are the examples mentioned: Example #1. Let’s create 2 line plots for 2 functions y1=sin(x1) and y2=sin(2.x2) where x1 ranges from 0 to 3.pi x2 ranges from pi/2.
Plot two graphs matlab
MATLAB Function Reference

I have two different contour plots (I attached codes and image), one is creating by thresholding and second by watershed. I would like to have one figure and all of contours in it (lungs, spine, boundary). Thank you for your answers.

subplot

Create axes object in tiled positions

Syntax

Description

subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane contains an axes object. Subsequent plots are output to the current pane.

h = subplot(m,n,p), or subplot(mnp) breaks the Figure window into an m-by-n matrix of small axes, selects the pth axes object for for the current plot, and returns the axis handle. The axes are counted along the top row of the Figure window, then the second row, etc. For example,

2 Plots 1 Figure Matlab

plots income on the top half of the window and outgo on the bottom half. If the CurrentAxes is nested in a uipanel, the panel is used as the parent for the subplot instead of the current figure. The new axes object becomes the current axes.

If p is a vector, it specifies an axes object having a position that covers all the subplot positions listed in p.

subplot(m,n,p,'replace')If the specified axes object already exists, delete it and create a new axes.

subplot(m,n,p,'align')positions the individual axes so that the plot boxes align, but does not prevent the labels and ticks from overlapping.

subplot(h)makes the axes object with handle h current for subsequent plotting commands.

subplot('Position',[left bottom width height])creates an axes at the position specified by a four-element vector. left, bottom, width, and height are in normalized coordinates in the range from 0.0 to 1.0.

Matlab 2 Plots On 1 Figure

h = subplot(...)returns the handle to the new axes object.

Remarks

If a subplot specification causes a new axes object to overlap any existing axes, then subplot deletes the existing axes object and uicontrol objects. However, if the subplot specification exactly matches the position of an existing axes object, then the matching axes object is not deleted and it becomes the current axes.

subplot(1,1,1) or clf deletes all axes objects and returns to the default subplot(1,1,1) configuration.

You can omit the parentheses and specify subplot as

where m refers to the row, n refers to the column, and p specifies the pane.

Special Case - subplot(111)

The command subplot(111) is not identical in behavior to subplot(1,1,1) and exists only for compatibility with previous releases. This syntax does not immediately create an axes object, but instead sets up the figure so that the next graphics command executes a clf reset (deleting all figure children) and creates a new axes object in the default position. This syntax does not return a handle, so it is an error to specify a return argument. (This behavior is implemented by setting the figure's NextPlot property to replace.)

Examples

To plot income in the top half of a figure and outgo in the bottom half,

The following illustration shows four subplot regions and indicates the command used to create each.

The following combinations produce asymmetrical arrangements of subplots.

You can also use the colon operator to specify multiple locations if they are in sequence.

See Also

axes, cla, clf, figure, gca

Basic Plots and Graphs for more information


sub2indsubsasgn

© 1994-2005 The MathWorks, Inc.


Line Plots

2 Plots 1 Figure Matlab Function

To create two-dimensional line plots, use the plot function. For example, plot the value of the sine function from 0 to 2π:

You can label the axes and add a title.

By adding a third input argument to the plot function, you can plot the same variables using a red dashed line.

'r--' is a line specification. Each specification can include characters for the line color, style, and marker. A marker is a symbol that appears at each plotted data point, such as a +, o, or *. For example, 'g:*' requests a dotted green line with * markers.

2 Plots 1 Figure Matlab

2 Plots 1 Figure Matlab Histogram

Notice that the titles and labels that you defined for the first plot are no longer in the current figure window. By default, MATLAB® clears the figure each time you call a plotting function, resetting the axes and other elements to prepare the new plot.

To add plots to an existing figure, use hold on. Until you use hold off or close the window, all plots appear in the current figure window.

3-D Plots

Three-dimensional plots typically display a surface defined by a function in two variables, z = f(x,y) .

2 Plots 1 Figure Matlab

Matlab 2 Plots Same Figure

To evaluate z, first create a set of (x,y) points over the domain of the function using meshgrid.

2 Plots 1 Figure Matlab

Then, create a surface plot.

Both the surf function and its companion mesh display surfaces in three dimensions. surf displays both the connecting lines and the faces of the surface in color. mesh produces wireframe surfaces that color only the lines connecting the defining points.

Matlab Plot Points

Subplots

You can display multiple plots in different subregions of the same window using the subplot function.

Plot Two Graphs Matlab

The first two inputs to subplot indicate the number of plots in each row and column. The third input specifies which plot is active. For example, create four plots in a 2-by-2 grid within a figure window.