xline — Draw vertical reference lines on current or specified axes with MATLAB-compatible styling forms.

xline adds one or more vertical reference lines with optional labels, line specs, and name-value styling, following MATLAB-compatible plotting behavior.

Syntax

h = xline(x)
h = xline(x, styleOrLabel)
h = xline(x, LineSpec, label)
h = xline(x, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
xNumericArrayYesX-coordinate scalar or numeric vector of vertical line positions.
style_or_labelAnyNoLineSpec token (for example '--r') or label text.
linespecStyleSpecYesLine style token (for example '--r').
labelStringScalarYesReference line label text.
propsAnyVariadicStyle arguments and Name/Value pairs (Color, LineWidth, LineStyle, LabelOrientation, Visible).

Returns

NameTypeDescription
hNumericArrayReference line handle scalar or row vector when multiple coordinates are provided.

Errors

IdentifierWhenMessage
RunMat:xline:InvalidArgumentCoordinate input, style arguments, or Name/Value pairs are invalid.xline: invalid argument
RunMat:xline:InternalInternal plotting state update fails.xline: internal operation failed

How xline works

  • xline(x) adds a vertical reference line at each coordinate in x.
  • Reference lines append to the current axes without replacing existing plot content.
  • Line spans follow the active axes limits, including later xlim and ylim changes.
  • The returned handle supports get and set for Value, Color, LineWidth, LineStyle, Label, LabelOrientation, DisplayName, and Visible.

Examples

Add a dashed threshold line

plot(1:10, rand(1, 10));
xline(5, '--r', 'Threshold');

Expected output:

% Adds a red dashed vertical reference line at x = 5

Add multiple reference lines

plot(1:10, rand(1, 10));
xline([2 5 8], ':');

Expected output:

% Adds three dotted vertical reference lines

Rendered xline example

time = 0:0.25:12;
temperature = 62 + 1.4*time + 5*sin(0.55*time).*exp(-0.08*time);

plot(time, temperature, 'LineWidth', 2);
xline(6, '--r', 'Control change', 'LineWidth', 1.5);
title('Temperature During Test Run');
xlabel('Time (min)');
ylabel('Temperature (C)');
grid on;
Expected output:
Equipment temperature time series with a vertical MATLAB xline marking a control change in RunMat

Compare this result with other chart types in the MATLAB Plot Gallery.

Using xline with coding agents

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

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

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.