# Matlab plot function ## Create 2-D Line Plot

Create a simple line plot and label the axes. Customize the appearance of plotted lines by changing the line color, the line style, and adding markers.

### Create Line Plot

Create a two-dimensional line plot using the function. For example, plot the value of the sine function from 0 to .

x = linspace(0,2*pi,100); y = sin(x); plot(x,y)

Label the axes and add a title.

xlabel('x') ylabel('sin(x)') title('Plot of the Sine Function')

### Plot Multiple Lines

By default, MATLAB clears the figure before each plotting command. Use the command to open a new figure window. You can plot multiple lines using the command. Until you use or close the window, all plots appear in the current figure window.

figure x = linspace(0,2*pi,100); y = sin(x); plot(x,y) hold on y2 = cos(x); plot(x,y2) hold off

### Change Line Appearance

You can change the line color, line style, or add markers by including an optional line specification when calling the function. For example:

• plots a dotted line.

• plots a green, dotted line.

• plots a green, dotted line with star markers.

• plots star markers with no line.

The symbols can appear in any order. You do not need to specify all three characteristics (line color, style, and marker). For more information about the different style options, see the function page.

For example, plot a dotted line. Add a second plot that uses a dashed, red line with circle markers.

x = linspace(0,2*pi,50); y = sin(x); plot(x,y,':') hold on y2 = cos(x); plot(x,y2,'--ro') hold off

Plot only the data points by omitting the line style option from the line specification.

x = linspace(0,2*pi,25); y = sin(x); plot(x,y,'o')

### Change Line Object Properties

You also can customize the appearance of the plot by changing properties of the object used to create the plot.

Create a line plot. Assign the object created to the variable . The display shows commonly used properties, such as , , and .

x = linspace(0,2*pi,25); y = sin(x); ln = plot(x,y)
ln = Line with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [0 0.2618 0.5236 0.7854 1.0472 1.3090 1.5708 1.8326 ... ] YData: [0 0.2588 0.5000 0.7071 0.8660 0.9659 1 0.9659 ... ] ZData: [1x0 double] Show all properties

To access individual properties, use dot notation. For example, change the line width to 2 points and set the line color to an RGB triplet color value, in this case . Add blue, circle markers.

ln.LineWidth = 2; ln.Color = [0 0.5 0.5]; ln.Marker = 'o'; ln.MarkerEdgeColor = 'b';

| | | Line Properties

### Related Topics

You have a modified version of this example. Do you want to open this example with your edits?

Sours: https://www.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html

## fplot

### Description

example

plots symbolic input over the default interval .

example

plots xt = x(t) and yt = y(t) over the default range of , which is .

example

uses to set the line style, marker symbol, and line color.

example

specifies line properties using one or more pair arguments. Use this option with any of the input argument combinations in the previous syntaxes. pair settings apply to all the lines plotted. To set options for individual lines, use the objects returned by .

plots into the axes specified by instead of the current axes .

### Plot Symbolic Expression

Plot over the default range of . shows poles by default. For details, see the argument in Name-Value Pair Arguments.

### Plot Symbolic Function

Plot the symbolic function over the default range .

syms f(x) f(x) = cos(x); fplot(f)

### Plot Parametric Curve

Plot the parametric curve and .

syms t x = cos(3*t); y = sin(2*t); fplot(x,y)

### Specify Plotting Interval

Plot over by specifying the plotting interval as the second input to .

syms x fplot(sin(x),[-pi/2 pi/2])

### Plot Multiple Lines on Same Figure

You can plot multiple lines either by passing the inputs as a vector or by using to successively plot on the same figure. If you specify and Name-Value arguments, they apply to all lines. To set options for individual plots, use the function handles returned by .

Divide a figure into two subplots using . On the first subplot, plot and using vector input. On the second subplot, plot and using .

syms x subplot(2,1,1) fplot([sin(x) cos(x)]) title('Multiple Lines Using Vector Inputs') subplot(2,1,2) fplot(sin(x)) hold on fplot(cos(x)) title('Multiple Lines Using hold on Command') hold off

### Change Line Properties and Display Markers

Plot three sine curves with a phase shift between each line. For the first line, use a linewidth of . For the second, specify a dashed red line style with circle markers. For the third, specify a cyan, dash-dot line style with asterisk markers. Display the legend.

syms x fplot(sin(x+pi/5),'Linewidth',2) hold on fplot(sin(x-pi/5),'--or') fplot(sin(x),'-.*c') legend('show','Location','best') hold off

### Control Resolution of Plot

Control the resolution of a plot by using the option. Increasing can make smoother, more accurate plots, while decreasing it can increase plotting speed.

Divide a figure into two by using . In the first subplot, plot a step function from to . The plot's resolution is too low to detect the step function. Fix this issue by increasing to in the second subplot. The plot now detects the step function and shows that by increasing you increased the plot's resolution.

syms x stepFn = rectangularPulse(2.1, 2.15, x); subplot(2,1,1) fplot(stepFn); title('Default MeshDensity = 23') subplot(2,1,2) fplot(stepFn,'MeshDensity',39); title('Increased MeshDensity = 39')

### Modify Plot After Creation

Plot . Specify an output to make return the plot object.

h = FunctionLine with properties: Function: sin(x) Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Show all properties

Change the default blue line to a dashed red line by using dot notation to set properties. Similarly, add markers and set the marker color to blue.

h.LineStyle = '--'; h.Color = 'r'; h.Marker = 'x'; h.MarkerEdgeColor = 'b';

### Add Title and Axis Labels and Format Ticks

For from to , plot . Add a title and axis labels. Create the x-axis ticks by spanning the x-axis limits at intervals of . Display these ticks by using the property. Create x-axis labels by using to apply to . Display these labels by using the property.

To use LaTeX in plots, see .

syms x fplot(sin(x),[-2*pi 2*pi]) grid on title('sin(x) from -2\pi to 2\pi') xlabel('x') ylabel('y') ax = gca; S = sym(ax.XLim(1):pi/2:ax.XLim(2)); ax.XTick = double(S); ax.XTickLabel = arrayfun(@texlabel,S,'UniformOutput',false);

### Re-evaluation on Zoom

When you zoom into a plot, re-evaluates the plot automatically. This re-evaluation on zoom reveals hidden detail at smaller scales.

Plot for and . Zoom in on the plot using and redraw the plot using . Because of re-evaluation on zoom, reveals smaller-scale detail. Repeat the zoom 6 times to view smaller-scale details. To play the animation, click the image.

syms x fplot(x^3*sin(1/x)); axis([-2 2 -0.02 0.02]); for i=1:6 zoom(1.7) pause(0.5) end

### Create Animations

Create animations by changing the displayed expression using the , , and properties and then by using to update the plot. To export to GIF, see .

By varying the variable i from 0.1 to 3, animate the parametric curve

To play the animation, click the image.

syms t fp = fplot(t, t); axis([-15 15 -15 15]) for i=0.1:0.05:3 fp.XFunction = i.*t.*sin(i*t); fp.YFunction = i.*t.*cos(i*t); drawnow end

collapse all

### — Expression or function to plotsymbolic expression | symbolic function

Expression or function to plot, specified as a symbolic expression or function.

### — Plotting interval for x-coordinates[–5 5] (default) | vector of two numbers

Plotting interval for x-coordinates, specified as a vector of two numbers. The default range is . However, if detects a finite number of discontinuities in , then expands the range to show them.

### — Parametric input for x-coordinatessymbolic expression | symbolic function

Parametric input for x-coordinates, specified as a symbolic expression or function. uses to find the parameter.

### — Parametric input for y-axissymbolic expression | symbolic function

Parametric input for y-axis, specified as a symbolic expression or function. uses to find the parameter.

### — Range of values of parameter [–5 5] (default) | vector of two numbers

Range of values of parameter , specified as a vector of two numbers. The default range is .

### — Axes objectaxes object

Axes object. If you do not specify an axes object, then uses the current axes .

### — Line style, marker, and colorcharacter vector | string

Line style, marker, and color, specified as a character vector or string containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line.

Example: is a red dashed line with circle markers

Line StyleDescriptionResulting Line
Solid line
Dashed line
Dotted line
Dash-dotted line
MarkerDescriptionResulting Marker
Circle
Plus sign
Asterisk
Point
Cross
Horizontal line
Vertical line
Square
Diamond
Upward-pointing triangle
Downward-pointing triangle
Right-pointing triangle
Left-pointing triangle
Pentagram
Hexagram
Color NameShort NameRGB TripletAppearance

### Name-Value Arguments

Specify optional comma-separated pairs of arguments. is the argument name and is the corresponding value. must appear inside quotes. You can specify several name and value pair arguments in any order as .

Example:

The function line properties listed here are only a subset. For a complete list, see FunctionLine Properties.

### — Number of evaluation points23 (default) | number

Number of evaluation points, specified as a number. The default is . Because uses adaptive evaluation, the actual number of evaluation points is greater.

### — Display asymptotes at poles (default) | on/off logical value

Display asymptotes at poles, specified as or , or as numeric or logical () or (). A value of is equivalent to true, and is equivalent to . Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type .

The asymptotes display as gray, dashed vertical lines. displays asymptotes only with the syntax or variants, and not with the syntax.

### — Line color (default) | RGB triplet | hexadecimal color code | | | | ...

Line color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

• An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range ; for example, .

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol () followed by three or six hexadecimal digits, which can range from to . The values are not case sensitive. Thus, the color codes , , , and are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.

Example:

Example:

Example:

### — Line style (default) | | | |

Line style, specified as one of the options listed in this table.

Line StyleDescriptionResulting Line
Solid line
Dashed line
Dotted line
Dash-dotted line
No lineNo line

### — Line width (default) | positive value

Line width, specified as a positive value in points, where 1 point = 1/72 of an inch. If the line has markers, then the line width also affects the marker edges.

The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.

### — Marker symbol (default) | | | | | ...

Marker symbol, specified as one of the values listed in this table. By default, the object does not display markers. Specifying a marker symbol adds markers at each data point or vertex.

MarkerDescriptionResulting Marker
Circle
Plus sign
Asterisk
Point
Cross
Horizontal line
Vertical line
Square
Diamond
Upward-pointing triangle
Downward-pointing triangle
Right-pointing triangle
Left-pointing triangle
Pentagram
Hexagram
No markersNot applicable

### — Marker outline color (default) | RGB triplet | hexadecimal color code | | | | ...

Marker outline color, specified as , an RGB triplet, a hexadecimal color code, a color name, or a short name. The default value of uses the same color as the property.

For a custom color, specify an RGB triplet or a hexadecimal color code.

• An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range ; for example, .

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol () followed by three or six hexadecimal digits, which can range from to . The values are not case sensitive. Thus, the color codes , , , and are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

### — Marker fill color (default) | | RGB triplet | hexadecimal color code | | | | ...

Marker fill color, specified as , an RGB triplet, a hexadecimal color code, a color name, or a short name. The value uses the same color as the property.

For a custom color, specify an RGB triplet or a hexadecimal color code.

• An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range ; for example, .

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol () followed by three or six hexadecimal digits, which can range from to . The values are not case sensitive. Thus, the color codes , , , and are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

Example:

Example:

Example:

### — Marker size (default) | positive value

Marker size, specified as a positive value in points, where 1 point = 1/72 of an inch.

collapse all

### — One or more function or parameterized line objectsscalar | vector

One or more function or parameterized function line objects, returned as a scalar or a vector.

• If you use the syntax or a variation of this syntax, then returns function line objects.

• If you use the syntax or a variation of this syntax, then returns parameterized line objects.

You can use these objects to query and modify properties of a specific line. For a list of properties, see FunctionLine Properties and ParameterizedFunctionLine Properties.

### Tips

• If detects a finite number of discontinuities in , then expands the range to show them.

### Properties

Introduced in R2016a

You have a modified version of this example. Do you want to open this example with your edits?

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

### How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Sours: https://www.mathworks.com/help/symbolic/fplot.html

## plot

• ### Description

example

creates a 2-D line plot of the data in versus the corresponding values in .

• To plot a set of coordinates connected by line segments, specify and as vectors of the same length.

• To plot multiple sets of coordinates on the same set of axes, specify at least one of or as a matrix.

creates the plot using the specified line style, marker, and color.

example

plots multiple pairs of x- and y-coordinates on the same set of axes. Use this syntax as an alternative to specifying coordinates as matrices.

example

assigns specific line styles, markers, and colors to each x-y pair. You can specify for some x-y pairs and omit it for others. For example, specifies markers for the first x-y pair but not for the second pair.

example

plots against an implicit set of x-coordinates.

• If is a vector, the x-coordinates range from 1 to .

• If is a matrix, the plot contains one line for each column in . The x-coordinates range from 1 to the number of rows in .

If contains complex numbers, MATLAB® plots the imaginary part of versus the real part of . If you specify both and , the imaginary part is ignored.

specifies line style, marker, and color.

example

specifies properties using one or more name-value arguments. The properties apply to all the plotted lines. Specify the name-value arguments after all the arguments in any of the previous syntaxes. For a list of properties, see Line Properties.

example

displays the plot in the target axes. Specify the axes as the first argument in any of the previous syntaxes.

example

returns a object or an array of objects. Use to modify properties of the plot after creating it. For a list of properties, see Line Properties.

collapse all

### Create Line Plot

Create as a vector of linearly spaced values between 0 and . Use an increment of between the values. Create as sine values of . Create a line plot of the data.

x = 0:pi/100:2*pi; y = sin(x); plot(x,y)

### Plot Multiple Lines

Define as 100 linearly spaced values between and . Define and as sine and cosine values of . Create a line plot of both sets of data.

x = linspace(-2*pi,2*pi); y1 = sin(x); y2 = cos(x); figure plot(x,y1,x,y2)

### Create Line Plot From Matrix

Define as the 4-by-4 matrix returned by the function.

Y = 4×4 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1

Create a 2-D line plot of . MATLAB® plots each matrix column as a separate line.

### Specify Line Style

Plot three sine curves with a small phase shift between each line. Use the default line style for the first line. Specify a dashed line style for the second line and a dotted line style for the third line.

x = 0:pi/100:2*pi; y1 = sin(x); y2 = sin(x-0.25); y3 = sin(x-0.5); figure plot(x,y1,x,y2,'--',x,y3,':')

MATLAB® cycles the line color through the default color order.

### Specify Line Style, Color, and Marker

Plot three sine curves with a small phase shift between each line. Use a green line with no markers for the first sine curve. Use a blue dashed line with circle markers for the second sine curve. Use only cyan star markers for the third sine curve.

x = 0:pi/10:2*pi; y1 = sin(x); y2 = sin(x-0.25); y3 = sin(x-0.5); figure plot(x,y1,'g',x,y2,'b--o',x,y3,'c*')

### Display Markers at Specific Data Points

Create a line plot and display markers at every fifth data point by specifying a marker symbol and setting the property as a name-value pair.

x = linspace(0,10); y = sin(x); plot(x,y,'-o','MarkerIndices',1:5:length(y))

### Specify Line Width, Marker Size, and Marker Color

Create a line plot and use the option to specify a dashed green line with square markers. Use pairs to specify the line width, marker size, and marker colors. Set the marker edge color to blue and set the marker face color using an RGB color value.

x = -pi:pi/10:pi; y = tan(sin(x)) - sin(tan(x)); figure plot(x,y,'--gs',...'LineWidth',2,...'MarkerSize',10,...'MarkerEdgeColor','b',...'MarkerFaceColor',[0.5,0.5,0.5])

### Add Title and Axis Labels

Use the function to define as a vector of 150 values between 0 and 10. Define as cosine values of .

x = linspace(0,10,150); y = cos(5*x);

Create a 2-D line plot of the cosine curve. Change the line color to a shade of blue-green using an RGB color value. Add a title and axis labels to the graph using the , , and functions.

figure plot(x,y,'Color',[0,0.7,0.9]) title('2-D Line Plot') xlabel('x') ylabel('cos(5x)')

### Plot Durations and Specify Tick Format

Define as seven linearly spaced values between 0 and 3 minutes. Plot random data and specify the format of the tick marks using the name-value pair argument.

t = 0:seconds(30):minutes(3); y = rand(1,7); plot(t,y,'DurationTickFormat','mm:ss')

### Specify Axes for Line Plot

Starting in R2019b, you can display a tiling of plots using the and functions. Call the function to create a 2-by-1 tiled chart layout. Call the function to create an axes object and return the object as . Create the top plot by passing to the function. Add a title and y-axis label to the plot by passing the axes to the and functions. Repeat the process to create the bottom plot.

% Create data and 2-by-1 tiled chart layout x = linspace(0,3); y1 = sin(5*x); y2 = sin(15*x); tiledlayout(2,1) % Top plot ax1 = nexttile; plot(ax1,x,y1) title(ax1,'Top Plot') ylabel(ax1,'sin(5x)') % Bottom plot ax2 = nexttile; plot(ax2,x,y2) title(ax2,'Bottom Plot') ylabel(ax2,'sin(15x)')

### Modify Lines After Creation

Define as 100 linearly spaced values between and . Define and as sine and cosine values of . Create a line plot of both sets of data and return the two chart lines in .

x = linspace(-2*pi,2*pi); y1 = sin(x); y2 = cos(x); p = plot(x,y1,x,y2);

Change the line width of the first line to 2. Add star markers to the second line. Use dot notation to set properties.

p(1).LineWidth = 2; p(2).Marker = '*';

### Plot Circle

Plot a circle centered at the point (4,3) with a radius equal to 2. Use to use equal data units along each coordinate direction.

r = 2; xc = 4; yc = 3; theta = linspace(0,2*pi); x = r*cos(theta) + xc; y = r*sin(theta) + yc; plot(x,y) axis equal

collapse all

### — x-coordinatesscalar | vector | matrix

x-coordinates, specified as a scalar, vector, or matrix. The size and shape of depends on the shape of your data and the type of plot you want to create. This table describes the most common situations.

Type of PlotHow to Specify Coordinates
Single point

Specify and as scalars and include a marker. For example:

One set of points

Specify and as any combination of row or column vectors of the same length. For example:

Multiple sets of points
(using vectors)

Specify consecutive pairs of and vectors. For example:

plot([1 2 3],[4 5 6],[1 2 3],[7 8 9])
Multiple sets of points
(using matrices)

If all the sets share the same x- or y-coordinates, specify the shared coordinates as a vector and the other coordinates as a matrix. The length of the vector must match one of the dimensions of the matrix. For example:

plot([1 2 3],[4 5 6; 7 8 9])
If the matrix is square, MATLAB plots one line for each column in the matrix.

Alternatively, specify and as matrices of equal size. In this case, MATLAB plots each column of against the corresponding column of . For example:

plot([1 2 3; 4 5 6],[7 8 9; 10 11 12])

Data Types: | | | | | | | | | | | |

### — y-coordinatesscalar | vector | matrix

y-coordinates, specified as a scalar, vector, or matrix. The size and shape of depends on the shape of your data and the type of plot you want to create. This table describes the most common situations.

Type of PlotHow to Specify Coordinates
Single point

Specify and as scalars and include a marker. For example:

One set of points

Specify and as any combination of row or column vectors of the same length. For example:

Alternatively, specify just the y-coordinates. For example:

Multiple sets of points
(using vectors)

Specify consecutive pairs of and vectors. For example:

plot([1 2 3],[4 5 6],[1 2 3],[7 8 9])
Multiple sets of points
(using matrices)

If all the sets share the same x- or y-coordinates, specify the shared coordinates as a vector and the other coordinates as a matrix. The length of the vector must match one of the dimensions of the matrix. For example:

plot([1 2 3],[4 5 6; 7 8 9])
If the matrix is square, MATLAB plots one line for each column in the matrix.

Alternatively, specify and as matrices of equal size. In this case, MATLAB plots each column of against the corresponding column of . For example:

plot([1 2 3; 4 5 6],[7 8 9; 10 11 12])

Data Types: | | | | | | | | | | | |

### — Line style, marker, and colorcharacter vector | string

Line style, marker, and color, specified as a character vector or string containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line.

Example: is a red dashed line with circle markers

Line StyleDescriptionResulting Line
Solid line
Dashed line
Dotted line
Dash-dotted line
MarkerDescriptionResulting Marker
Circle
Plus sign
Asterisk
Point
Cross
Horizontal line
Vertical line
Square
Diamond
Upward-pointing triangle
Downward-pointing triangle
Right-pointing triangle
Left-pointing triangle
Pentagram
Hexagram
Color NameShort NameRGB TripletAppearance

### — Target axes object | object | object

Target axes, specified as an object, a object, or a object. If you do not specify the axes, MATLAB plots into the current axes or it creates an object if one does not exist.

To create a polar plot or geographic plot, specify as a or object. Alternatively, call the or function.

### Name-Value Arguments

Specify optional comma-separated pairs of arguments. is the argument name and is the corresponding value. must appear inside quotes. You can specify several name and value pair arguments in any order as .

Example:

The chart line properties listed here are only a subset. For a complete list, see Line Properties.

### — Line color (default) | RGB triplet | hexadecimal color code | | | | ...

Line color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

• An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range ; for example, .

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol () followed by three or six hexadecimal digits, which can range from to . The values are not case sensitive. Thus, the color codes , , , and are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

Example:

Example:

Example:

### — Line style (default) | | | |

Line style, specified as one of the options listed in this table.

Line StyleDescriptionResulting Line
Solid line
Dashed line
Dotted line
Dash-dotted line
No lineNo line

### — Line width (default) | positive value

Line width, specified as a positive value in points, where 1 point = 1/72 of an inch. If the line has markers, then the line width also affects the marker edges.

The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.

### — Marker symbol (default) | | | | | ...

Marker symbol, specified as one of the values listed in this table. By default, the object does not display markers. Specifying a marker symbol adds markers at each data point or vertex.

MarkerDescriptionResulting Marker
Circle
Plus sign
Asterisk
Point
Cross
Horizontal line
Vertical line
Square
Diamond
Upward-pointing triangle
Downward-pointing triangle
Right-pointing triangle
Left-pointing triangle
Pentagram
Hexagram
No markersNot applicable

### — Indices of data points at which to display markers (default) | vector of positive integers | scalar positive integer

Indices of data points at which to display markers, specified as a vector of positive integers. If you do not specify the indices, then MATLAB displays a marker at every data point.

Note

To see the markers, you must also specify a marker symbol.

Example: displays a circle marker at the first, fifth, and tenth data points.

Example: displays a cross marker every three data points.

Example: displays one square marker at the fifth data point.

### — Marker outline color (default) | RGB triplet | hexadecimal color code | | | | ...

Marker outline color, specified as , an RGB triplet, a hexadecimal color code, a color name, or a short name. The default value of uses the same color as the property.

For a custom color, specify an RGB triplet or a hexadecimal color code.

• An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range ; for example, .

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol () followed by three or six hexadecimal digits, which can range from to . The values are not case sensitive. Thus, the color codes , , , and are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

### — Marker fill color (default) | | RGB triplet | hexadecimal color code | | | | ...

Marker fill color, specified as , an RGB triplet, a hexadecimal color code, a color name, or a short name. The option uses the same color as the property of the parent axes. If you specify and the axes plot box is invisible, the marker fill color is the color of the figure.

For a custom color, specify an RGB triplet or a hexadecimal color code.

• An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range ; for example, .

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol () followed by three or six hexadecimal digits, which can range from to . The values are not case sensitive. Thus, the color codes , , , and are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

### — Marker size (default) | positive value

Marker size, specified as a positive value in points, where 1 point = 1/72 of an inch.

### — Format for tick labelscharacter vector | string

Format for tick labels, specified as the comma-separated pair consisting of and a character vector or string containing a date format. Use the letters and to construct a custom format. These letters correspond to the Unicode® Locale Data Markup Language (LDML) standard for dates. You can include non-ASCII letter characters such as a hyphen, space, or colon to separate the fields.

If you do not specify a value for , then automatically optimizes and updates the tick labels based on the axis limits.

Example: displays a date and time such as .

The following table shows several common display formats and examples of the formatted output for the date, Saturday, April 19, 2014 at 9:41:06 PM in New York City.

Value of Example

For a complete list of valid letter identifiers, see the property for datetime arrays.

is not a chart line property. You must set the tick format using the name-value pair argument when creating a plot. Alternatively, set the format using the and functions.

The property of the datetime ruler stores the format.

### — Format for tick labelscharacter vector | string

Format for tick labels, specified as the comma-separated pair consisting of and a character vector or string containing a duration format.

If you do not specify a value for , then automatically optimizes and updates the tick labels based on the axis limits.

To display a duration as a single number that includes a fractional part, for example, 1.234 hours, specify one of the values in this table.

Value of Description
Number of exact fixed-length years. A fixed-length year is equal to 365.2425 days.
Number of exact fixed-length days. A fixed-length day is equal to 24 hours.
Number of hours
Number of minutes
Number of seconds

Example: displays duration values in terms of fixed-length days.

To display a duration in the form of a digital timer, specify one of these values.

In addition, you can display up to nine fractional second digits by appending up to nine characters.

Example: displays the milliseconds of a duration value to three digits.

is not a chart line property. You must set the tick format using the name-value pair argument when creating a plot. Alternatively, set the format using the and functions.

The property of the duration ruler stores the format.

### Tips

• Use and values to create breaks in the lines. For example, this code plots the first two elements, skips the third element, and draws another line using the last two elements:

• uses colors and line styles based on the and properties of the axes. cycles through the colors with the first line style. Then, it cycles through the colors again with each additional line style.

Starting in R2019b, you can change the colors and the line styles after plotting by setting the or properties on the axes. You can also call the function to change the color order for all the axes in the figure.

### Tall ArraysCalculate with arrays that have more rows than fit in memory.

Usage notes and limitations:

• Supported syntaxes for tall arrays and are:

• must be in monotonically increasing order.

• Categorical inputs are not supported.

• Tall inputs must be real column vectors.

• With tall arrays, the function plots in iterations, progressively adding to the plot as more data is read. During the updates, a progress indicator shows the proportion of data that has been plotted. Zooming and panning is supported during the updating process, before the plot is complete. To stop the update process, press the pause button in the progress indicator.

### GPU ArraysAccelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

Usage notes and limitations:

• This function accepts GPU arrays, but does not run on a GPU.

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

### Distributed ArraysPartition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.

Usage notes and limitations:

• This function operates on distributed arrays, but executes in the client MATLAB.

For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

### Properties

Introduced before R2006a

You have a modified version of this example. Do you want to open this example with your edits?

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

### How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Sours: https://www.mathworks.com/help/matlab/ref/plot.html
Matlab Tutorial - 60 - Plotting Functions

## MATLAB Plot Function ### Introduction to MATLAB Plot Function

MATLAB or Matrix Laboratory is a programming language that was developed by MathWorks. This powerful language finds its utility in technical computing. MATLAB provides us with a convenient environment that can be used to integrate tasks like manipulations on matrix, plotting data and functions, implementing algorithms, creating user interfaces, etc. MATLAB is also convenient as it gives the solutions in the form that its user can easily understand. It uses mathematical notations to display the solutions.

### Where can MATLAB be used?

Below are a few areas where we can use MATLAB:

• Computation
• Development of Algorithms
• Modeling
• Simulation
• Prototyping
• Analysis and Visualization of data
• Scientific graphs
• Engineering graphics
• Developing applications

MATLAB comprises a number of techniques to perform the above-mentioned uses. The objective of this article is to have a thorough understanding of plot functions in MATLAB. As the name suggests, the purpose of the plot function is to plot the graph of a function in MATLAB. We use a plot function to create a graphical representation of our data. It is straightforward and easy to visualize a trend in data when it is plotted as compared to just looking at the raw figures.

### Syntax of Plot Function

Below are the syntax of Plot Function:

• fplot (f)
• fplot (f, xinterval)
• fplot (funx, funy)
• fplot (___, LineSpec)
• fplot (___, Name, Value)
• fp = fplot (___)

Let us now understand all the above-mentioned functions one by one:

#### 1. fplot (f)

This will plot the graph defined by the function y = f(x). The plot is created over the default interval [-5, 5].

Let’s understand this function with the help of an example:

Here we have taken square function as the one which we need to plot. The output of our example will be as shown below: #### 2. fplot (f, xinterval)

In the above example, the interval was defaulting, however, if we need the interval of our choice, we can use fplot (f, xinterval). We need to specify the interval as a 2-element vector in the form [xmin xmax]

Let’s understand this clearly with the help of an example:

Here we have taken the same function as in the example above. For this example, we will take the interval 0 to 3. The output of our example will be as shown below: #### 3. fplot (funx, funy)

This function will plot the 2 functions passed as arguments. Here we define 2 functions ‘at’ and ‘bt’ as follows:

The output of the final function fplot (at, bt), will be #### 4. fplot (___, LineSpec)

This function is used to get the marker symbol, line style or color of the plotline as per the choice of user. i.e user can decide how he/she wants to visualize the final output.

For example, if we need to plot a graph of red color, we will pass ‘r’ as the argument in any of the functions explained above.

Here is an example to understand this:

Example:

The output that we will get here will be a red color plot of square function: Similarly, we can use ‘b’ for blue color and ‘y’ for yellow color.

#### 5. fplot (__, name, value)

This function is used to define properties of the line in the plot as per the pair of name-value passed in the argument. For example, if we pass ‘Linewidth’, 3 as an argument in any of the above examples, we will get a plot of width 3.

Here is an example to understand this: #### 6. fp = fplot (___)

This function is used to modify the properties of an existing plot. So, we can change the properties of a plot that is already created, by using this function.

Let us first draw plot for a sin wave using the function fp = fplot (@(x) sin(x))

Let us now understand various ways in which we can modify properties of our plot obtained from fp:

• To change the line of the plot into a line with colons, we can use fp.LineStyle = ‘:’;
• To change the color of the line, we can use fp.Color = ‘r’;
• To get marker points on the plot, we can use fp.Marker = ‘x’;
• To get the desired color of the markers, we can use fp.MarkerEdgeColor = ‘b’;

After implementing the above functions, our final output will be: ### Conclusion

MATLAB is a system whose basic data element is an array that does not require any dimensioning. This allows us to solve computing problems, especially the problems with matrix & vector formulations. In addition to its computing powers, MATLAB also provides its users the ability to draw and visualize the data for better understanding and drawing inferences.

All this is done in a significantly less amount of time when compared to writing a program in a scalar and non-interactive language such as C.

### Recommended Articles

This is a guide to MATLAB Plot Function. Here we discuss Where can MATLAB be used along with the Syntax and outputs. You can also go through our other suggested articles to learn more–

1. Plot Function in R
2. Matlab Features
3. Pie Chart in MATLAB
4. Colors in Matlab
5. Complete Guide to Matlab Comet()
6. Guide to How to Use Matlab?
7. Algorithm to Implement Matlab LineWidth
8. Vector in Java | How to Create? | Examples
Sours: https://www.educba.com/matlab-plot-function/

## The Plot Function

The plot function usually takes two arguments (but can take one). The first is the X values of the points to plot, and the second is the Y value of the points to plot. Below is an example of creating and plotting the values of the X squared graph from -10 to +10. In the case of a single argument, the X axis becomes 1,2,3,4,... up to the length of the array, and the Y axis contains the values of the array.

Notice that plot will "connect the dots" for you, drawing lines between each set of X,Y values.

If you have a single array that you wish to plot, and don't really care about the X axis, you just want to see the values plotted in the Y axis, you can pass a single array to the plot function. Here is an example:

The following functions are almost always used with plot to make the output more readable.

1. xlabel, ylabel : Provide a labeling for the graph axii.
2. title : Provide a title for the graph.
3. legend: Provide a legend telling what multiple graph lines mean.
4. grid: Put a checkered grid over the graph (add more lines to (sometimes) make it easier to see values.
5. axis: Tell how big of an area the graph should display.

Sometimes you will want to "clear" the figure. This is normally done by simply "plotting" the next thing you want. Alternatively, you can use the "clf" command:

Sometimes you will want to plot multiple graphs on the XY axis (on the same figure). In Matlab, when you use the plot function more than once, each time you call it, the previous figure is "erased".

To make a previous figure remain on the plot, we use the "hold on;" command. When we want to resume clearing the figure for each new plot, we use the "hold off;" command.

Try the following code:

You should have only seen one graph, the cubed graph (which was the second plot above). Now try this code, using the "hold on;" command.

Sometimes you will want to place multiple plots side by side on a single figure. You can achieve this by using the Matlab subplot function.

For many more details on this function (as well as the commands and functions mentioned above) you can always use the help command at the Matlab prompt.

The parameters used by the subplot function determine how many rows and columns for the overall "matrix" of figures, and then which of these positions to put the next plot in. The parameters are: 1) The number of rows, 2) the number of columns, 3) which of the sub plots to use.

Here is an example of how to create a 2x3 matrix (6 figures) of plots and to address each one of them by a number (shown below). Notice how row 1, column 1, is identified by the number 1. Row one, column three is identified by 3. Row two, column one, "wraps" and is identified by 4.:

Columns
onetwothree
Rowsone123
two456

Test this code. Notice that the subplot command stays the same, except for the "index" into which matrix location you want. Also notice that you can title, label, etc, each plot.

Matlab provides several well known graphing functions, including histograms, pie charts, and stem charts.

1. Histograms: Histograms are used to show how many values in an array of values fall within certain "bins". For example, if we have the scores of all students on a test, we may want to find out how many scores were between 90-100, 80-90, 70-80, etc. The histogram is the perfect tool for this.

2. Pie Charts: Pie Charts are useful for showing what percentage of a whole, each element represents. For example, if we knew there were 40 hours in the week, we could use a pie chart to show how many hours were spent on study, sleep, play, etc

3. Stem Charts: The stem chart draws a line from the bottom of the graph to the appropriate Y value for each X value. For example if the X axis represents how many times a letter was found in a document, we could use a stem plot to show the relationship between all letters, and how often they occur..

Sours: https://www.cs.utah.edu/~germain/PPS/Topics/Matlab/plot.html
MATLAB Plot Function Tutorial

## MATLAB - Plotting

To plot the graph of a function, you need to take the following steps −

• Define x, by specifying the range of values for the variable x, for which the function is to be plotted

• Define the function, y = f(x)

• Call the plot command, as plot(x, y)

Following example would demonstrate the concept. Let us plot the simple function y = x for the range of values for x from 0 to 100, with an increment of 5.

Create a script file and type the following code −

x = [0:5:100]; y = x; plot(x, y)

When you run the file, MATLAB displays the following plot − Let us take one more example to plot the function y = x2. In this example, we will draw two graphs with the same function, but in second time, we will reduce the value of increment. Please note that as we decrease the increment, the graph becomes smoother.

Create a script file and type the following code −

x = [1 2 3 4 5 6 7 8 9 10]; x = [-100:20:100]; y = x.^2; plot(x, y)

When you run the file, MATLAB displays the following plot − Change the code file a little, reduce the increment to 5 −

x = [-100:5:100]; y = x.^2; plot(x, y)

MATLAB draws a smoother graph − ### Adding Title, Labels, Grid Lines and Scaling on the Graph

MATLAB allows you to add title, labels along the x-axis and y-axis, grid lines and also to adjust the axes to spruce up the graph.

• The xlabel and ylabel commands generate labels along x-axis and y-axis.

• The title command allows you to put a title on the graph.

• The grid on command allows you to put the grid lines on the graph.

• The axis equal command allows generating the plot with the same scale factors and the spaces on both axes.

• The axis square command generates a square plot.

### Example

Create a script file and type the following code −

x = [0:0.01:10]; y = sin(x); plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph'), grid on, axis equal

MATLAB generates the following graph − ### Drawing Multiple Functions on the Same Graph

You can draw multiple graphs on the same plot. The following example demonstrates the concept −

### Example

Create a script file and type the following code −

x = [0 : 0.01: 10]; y = sin(x); g = cos(x); plot(x, y, x, g, '.-'), legend('Sin(x)', 'Cos(x)')

MATLAB generates the following graph − ### Setting Colors on Graph

MATLAB provides eight basic color options for drawing graphs. The following table shows the colors and their codes −

CodeColor
wWhite
kBlack
bBlue
rRed
cCyan
gGreen
mMagenta
yYellow

### Example

Let us draw the graph of two polynomials

• f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and

• g(x) = 5x3 + 9x + 2

Create a script file and type the following code −

x = [-10 : 0.01: 10]; y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9; g = 5 * x.^3 + 9 * x + 2; plot(x, y, 'r', x, g, 'g')

When you run the file, MATLAB generates the following graph − ### Setting Axis Scales

The axis command allows you to set the axis scales. You can provide minimum and maximum values for x and y axes using the axis command in the following way −

axis ( [xmin xmax ymin ymax] )

The following example shows this −

### Example

Create a script file and type the following code −

x = [0 : 0.01: 10]; y = exp(-x).* sin(2*x + 3); plot(x, y), axis([0 10 -1 1])

When you run the file, MATLAB generates the following graph − ### Generating Sub-Plots

When you create an array of plots in the same figure, each of these plots is called a subplot. The subplot command is used for creating subplots.

Syntax for the command is −

subplot(m, n, p)

where, m and n are the number of rows and columns of the plot array and p specifies where to put a particular plot.

Each plot created with the subplot command can have its own characteristics. Following example demonstrates the concept −

### Example

Let us generate two plots −

y = e−1.5xsin(10x)

y = e−2xsin(10x)

Create a script file and type the following code −

x = [0:0.01:5]; y = exp(-1.5*x).*sin(10*x); subplot(1,2,1) plot(x,y), xlabel('x'),ylabel('exp(–1.5x)*sin(10x)'),axis([0 5 -1 1]) y = exp(-2*x).*sin(10*x); subplot(1,2,2) plot(x,y),xlabel('x'),ylabel('exp(–2x)*sin(10x)'),axis([0 5 -1 1])

When you run the file, MATLAB generates the following graph − Sours: https://www.tutorialspoint.com/matlab/matlab_plotting.htm

### Now discussing:

While they were driving, I found everything from him and took it away. I put a bag over his head so that he could keep quiet. Well, we bought a lot of vodka and drank at first, then the boys already wanted us. Tanya and I have already undressed, Sanya is such a bitch lying on her horse-radish looking, not sticking something. I finally can be so laughing.

48 49 50 51 52