MATLAB Function Reference |
Syntax
line(X,Y) line(X,Y,Z) line(X,Y,Z,'PropertyName
',PropertyValue,...) line('PropertyName
',PropertyValue,...) low-level-PN/PV pairs only h = line(...)
Description
line
creates a line object in the current axes. You can specify the color, width, line style, and marker type, as well as other characteristics.
The line
function has two forms:
MATLAB cycles through the axes ColorOrder
and LineStyleOrder
property values the way the plot
function does. However, unlike plot
, line
does not call the newplot
function.
MATLAB draws a line object in the current axes using the default line color (see the colordef
function for information on color defaults). Note that you cannot specify matrix coordinate data with the low-level form of the line
function.
line(X,Y)
adds the line defined in vectors X
and Y
to the current axes. If X
and Y
are matrices of the same size, line
draws one line per column.
line(X,Y,Z)
creates lines in three-dimensional coordinates.
line(X,Y,Z,'
creates a line using the values for the property name/property value pairs specified and default values for all other properties. PropertyName
',PropertyValue,...)
See the LineStyle
and Marker
properties for a list of supported values.
line('XData',x,'YData',y,'ZData',z,'
creates a line in the current axes using the property values defined as arguments. This is the low-level form of the PropertyName
',PropertyValue,..
.)
line
function, which does not accept matrix coordinate data as the other informal forms described above.
h = line(...)
returns a column vector of handles corresponding to each line object the function creates.
Remarks
In its informal form, the line
function interprets the first three arguments (two for 2-D) as the X
, Y
, and Z
coordinate data, allowing you to omit the property names. You must specify all other properties as name/value pairs. For example,
The low-level form of the line
function can have arguments that are only property name/property value pairs. For example,
Line properties control various aspects of the line object and are described in the "Line Properties" section. You can also set and query property values after creating the line using set
and get
.
You can specify properties as property name/property value pairs, structure arrays, and cell arrays (see the set
and get
reference pages for examples of how to specify these data types).
Unlike high-level functions such as plot
, line
does not respect the settings of the figure and axes NextPlot
properties. It simply adds line objects to the current axes. However, axes properties that are under automatic control, such as the axis limits, can change to accommodate the line within the current axes.
Examples
This example uses the line
function to add a shadow to plotted data. First, plot some data and save the line's handle:
Next, add a shadow by offsetting the x-coordinates. Make the shadow line light gray and wider than the default LineWidth
:
Finally, pop the first line to the front:
Input Argument Dimensions - Informal Form
This statement reuses the one-column matrix specified for ZData
to produce two lines, each having four points.
If all the data has the same number of columns and one row each, MATLAB transposes the matrices to produce data for plotting. For example,
This also applies to the case when just one or two matrices have one row. For example, the statement
Object Hierarchy
Setting Default Properties
You can set default line properties on the axes, figure, and root levels:
set(0,'DefaultLinePropertyName
',Property
Value,...) set(gcf,'DefaultLinePropertyName
',Property
Value,...) set(gca,'DefaultLinePropertyName
',Property
Value,...)
Where PropertyName
is the name of the line property and PropertyValue
is the value you are specifying. Use set
and get
to access line properties.
See Also
Object Creation Functions for related functions
Line Properties for property descriptions
lin2mu | Line Properties |
© 1994-2005 The MathWorks, Inc.