Line specification syntax
Description
LineSpec
is an argument to plotting functions, such as plot
, that defines three components used to specify lines in MATLAB:
For example,
plot(x,y,'-.ro')
plots y
versus x
using a dash-dot line (-.
), colored red (r
), and places circular markers (o
) at the data points. If you specify a marker, but no a linesytle, MATLAB plots only the markers.
The following tables list the symbols you use to define the line style, color, and marker. Specify these symbols (in any order) as a quoted string after the data arguments.
Symbol
|
Line Style
|
Symbol
|
Line Style
|
-
|
solid line (default)
|
:
|
dotted line
|
--
|
dashed line
|
-.
|
dash-dot line
|
Symbol
|
Color
|
Symbol
|
Color
|
y
|
yellow
|
g
|
green
|
m
|
magenta
|
b
|
blue
|
c
|
cyan
|
w
|
white
|
r
|
red
|
k
|
black
|
Marker Specifier
|
Description
|
+
|
plus sign
|
o
|
circle
|
*
|
asterisk
|
.
|
point
|
x
|
cross
|
s
|
square
|
d
|
diamond
|
^
|
upward pointing triangle
|
v
|
downward pointing triangle
|
>
|
right pointing triangle
|
<
|
left pointing triangle
|
p
|
five-pointed star (pentagram)
|
h
|
six-pointed star (hexagram)
|
Related Properties
When using the plot
and plot3
functions, you can also specify other characteristics of lines using graphics properties:
In addition, you can specify the LineStyle
, Color
, and Marker
properties instead of using the symbol string. This is useful if you want to specific a color that is not in the list by using RGB values. See the ColorSpec
for more information on color.
Examples
Plot the sine function over three different ranges using different line styles, colors, and markers:
t = 0:pi/20:2*pi;
plot(t,sin(t),'-.r*')
hold on
plot(sin(t-pi/2),'--mo')
plot(sin(t-pi),':bs')
hold off
Create a plot illustrating how to set line graphics properties:
plot(t,sin(2*t),'-mo',...
'LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[.49 1 .63],...
'MarkerSize',12)
See Also
line
, plot
, surface
, patch
, Axes
LineStyleOrder
propert.
[ Previous | Help Desk | Next ]