yline — Draw horizontal reference lines on the current axes.
yline adds one or more horizontal reference lines to the current axes. It accepts scalar or vector y-coordinates, MATLAB line specs, labels, and common line name/value styling such as Color, LineStyle, LineWidth, and DisplayName.
How yline works
yline(y)adds a horizontal reference line at each coordinate iny.- Reference lines append to the current axes without replacing existing plot content.
- Line spans follow the active axes limits, including later
xlimandylimchanges. - The returned handle supports
getandsetforValue,Color,LineWidth,LineStyle,Label,LabelOrientation,DisplayName, andVisible.
Examples
Add a zero baseline
plot(-5:5, (-5:5).^2 - 10);
yline(0, 'k', 'LineWidth', 1);Expected output:
% Adds a black horizontal reference line at y = 0Label a baseline
plot(1:10, rand(1, 10));
yline(0.5, ':', 'Baseline', 'LabelOrientation', 'horizontal');Expected output:
% Adds a dotted labeled horizontal reference lineRelated Plotting functions
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.