line — Create low-level 2-D or 3-D line graphics objects in MATLAB and RunMat.

line creates line graphics objects directly without clearing the current axes. It supports positional X,Y and X,Y,Z data, property constructors with XData, YData, and ZData, axes targeting, matrix column expansion, style strings, and common line name/value properties.

Syntax

h = line(X, Y)
h = line(X, Y, Z)
h = line(X, Y, Name, Value, ...)
h = line(Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
XNumericArrayYesX data.
YNumericArrayYesY data.
ZNumericArrayYesZ data.
propsAnyVariadicName/value pairs such as XData, YData, ZData, Color, LineWidth, and DisplayName.

Returns

NameTypeDescription
hNumericArrayLine graphics handle scalar or row vector when matrix data creates multiple lines.

Errors

IdentifierWhenMessage
RunMat:line:InvalidArgumentLine data, axes target, style arguments, or Name/Value pairs are invalid.line: invalid argument
RunMat:line:InternalInternal plotting state update fails.line: internal operation failed

How line works

  • line(X,Y) creates a 2-D line object from vector data and returns its graphics handle.
  • line(X,Y,Z) creates a 3-D line object and returns a line handle with XData, YData, and ZData properties.
  • Matrix X and Y inputs with matching size create one line per column and return a row vector of handles. A vector paired with a matrix is reused for each matrix column when its length matches the matrix height.
  • line('XData',x,'YData',y,...) supports low-level graphics construction, including Parent for explicit axes targeting.
  • line appends to the target axes regardless of the current hold mode, matching MATLAB's low-level graphics-object behavior.
  • Returned handles work with get and set for line data, color, line style, line width, marker, display name, and visibility properties.

Options

  • XData, YData, and ZData provide constructor data in name/value form.
  • Parent accepts an axes handle and routes construction to that axes.
  • Style strings such as 'r--o', ':', and 'k' are accepted after positional data.
  • Common line properties include Color, LineWidth, LineStyle, Marker, MarkerSize, MarkerFaceColor, MarkerEdgeColor, DisplayName, and Visible.

Does RunMat run line on the GPU?

On the 2-D vector happy path, RunMat reuses exported plot input buffers and emits renderer-ready line geometry without a full host round-trip.

Reading data properties from a GPU-backed line can materialize source buffers; replacing XData or YData with set converts the object to host-backed line data while preserving handle semantics.

GPU memory and residency

line preserves GPU residency for simple 2-D vector inputs when the shared plotting context can consume exported GPU buffers directly. Matrix expansion, 3-D construction, and property-only forms gather to host data before registering the graphics object. GPU-backed handles still support get(h,'XData') and get(h,'YData') by reading back source buffers when those properties are requested.

Examples

Create a low-level 2-D line object

x = 0:0.1:1;
y = x.^2;
h = line(x, y, 'Color', 'r', 'LineWidth', 2);

Expected output:

% h is a numeric line handle

Construct a line from graphics data properties

h = line('XData', [1 2 3], 'YData', [4 5 6], 'DisplayName', 'samples');
get(h, 'Type')

Expected output:

ans =
    'line'

Create one line per matrix column

x = [1 1; 2 2; 3 3];
y = [1 3; 2 2; 3 1];
h = line(x, y);

Expected output:

% h is a 1-by-2 row vector of line handles

Create a 3-D line object

t = linspace(0, 2*pi, 100);
h = line(cos(t), sin(t), t, 'LineStyle', '--');

Expected output:

% h is a line handle with XData, YData, and ZData

Using line with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how line changes the result.

Run a small line example, explain the result, then change one input and compare the output.

FAQ

How is line different from plot?

plot is a high-level charting command and clears the active axes unless hold on is enabled. line is a low-level graphics-object constructor, so it appends line objects to the target axes without requiring hold on.

Can I update line data after creating the object?

Yes. Use set(h, 'XData', x, 'YData', y) for 2-D lines or also set ZData for 3-D lines. RunMat updates the stored geometry and invalidates cached render data.

What does line return for matrix inputs?

Each matrix column becomes one line object. The return value is a row vector of graphics handles in column order.

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how line is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.