Simple xline with all options

209 views (last 30 days)
Hagen Übele
Hagen Übele on 25 Oct 2021
Commented: Steven Lord on 2 Feb 2022
I simply want to add an xline with
a specified position, a specified color, a specified linewidth, a label and a specified label position.
I have tried every pertubation of what I think is possible, but it never works. Best I can achieve is a line with a specified color and a label on the left side. As soon as I try to add a linewidth it only returns invalid parameter/value pair.
It would be very helfpful if somebody could tell me how this is supposed to work.

Answers (1)

Steven Lord
Steven Lord on 25 Oct 2021
From the documentation, note that labels comes after the LineSpec but before any name-value pair arguments as stated in the fourth syntax in the Description section.
xline(0.5, 'r--', ... % This is the LineSpec, the label comes next
'$x = \frac{1}{2}$', ... % Only name-value pair arguments after this point
'LineWidth', 3, ...
'Interpreter', 'latex', ...
'LabelOrientation', 'horizontal')
  2 Comments
CAME18
CAME18 on 2 Feb 2022
Is there any way to have the label with a different color than the line?. For example:
in the example you provided, have the label with black letters instead of red, as the line's color.
Steven Lord
Steven Lord on 2 Feb 2022
There's no ConstantLine property for this, but if you leave the Interpreter property set to 'tex' (the default) you could include \color in your label. See the Interpreter section on this documentation page for a list of the supported markup available for use in TeX labels.
h = xline(0.5, 'r:', ... % line specification
'\color{black}black \color{red}and \color{blue}blue', ... % label text
'LineWidth', 4, ... % name-value pair arguments from this point on
'LabelOrientation', 'horizontal');

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!