The plot command serves as the fundamental tool for rendering two-dimensional graphs within the MATLAB environment. When invoked with two vector arguments, such as plot(horizontal, vertical), the system maps the values of the second argument against the first. If matrix inputs are provided, the function iterates through columns or rows depending on dimension alignment. In scenarios where a scalar is paired with a vector, discrete vertical points are generated at the scalar's position.
Calling the function with a single argument, plot(data), renders the columns of the input matrix against their respective indices. For complex number inputs, the real component is treated as the horizontal axis and the imaginary component as the vertical axis automatically.
Visual customization is achieved through a format string argument. This string allows the user to define color, marker style, and line type simultaneously.
| Color Spec | Appearance | Marker Spec | Appearance | Line Spec | Appearance |
|---|---|---|---|---|---|
| b | blue | . | point | - | solid |
| g | green | o | circle | : | dotted |
| r | red | x | cross | -. | dash-dot |
| c | cyan | + | plus | -- | dashed |
| m | magenta | * | star | ||
| y | yellow | s | square | ||
| k | black | d | diamond | ||
| w | white | ^ | triangle (up) |
For instance, executing plot(time, signal, 'r--o') generates a red dashed line with circle markers at each data point. Conversely, plot(x, y, 'ks') displays black squares without connecting lines.
Multiple datasets can be rendered in a single figure window by chaining pairs of coordinates and format strings. The syntax plot(x1, y1, style1, x2, y2, style2) overlays the specified series. As an example, plot(t, sin(t), 'b-', t, cos(t), 'g:') draws a solid blue sine wave alongside a dotted green cosine wave.
If no specific color is defined, the system cycles through the default ColorOrder property of the axes. Similarly, marker and line styles default to none and solid respectively unless overridden.
Advanced customization is available via property name and value pairs appended to the command. Properties such as LineWidth or specific RGB color values can be adjusted direct.
plot(x_vals, y_vals, 'LineWidth', 2.5, 'Color', [0.2 0.6 0.3]);
This command produces a line with increased thickness and a specific dark green shade defined by the RGB vector.