logo

How to Specify Colors, Line Styles, and Marker Types in MATLAB Graphs 📂Programing

How to Specify Colors, Line Styles, and Marker Types in MATLAB Graphs

Properties

The properties of a graph can be specified as follows.

Graph ColorMarkerLine Style
Red rDot .Solid -
Green gStar *Dotted :
Blue bX xDash-dot -.
Black kCircle o (letter o)Dashed --
Yellow yPlus +
Magenta mSquare s
White wDiamond d
Cyan cStar p
Triangle down v
Triangle up ^
Triangle left <
Triangle right >
Hexagon h

Example

mat_plot.png

x=linspace(0,1,20);
y=x.^3+3.*x.^2+3.*x+1;

figure()
plot(x,y,'ro')
hold on
plot(x,y+1,'g-')
plot(x,y+2,'c:')
plot(x,y+3,'k--')
legend({'ro', 'g-', 'c:', 'k--'})