Can I change the color of the label in xline / yline to be different from the color of the line?
75 views (last 30 days)
Show older comments
Michael Mazack
on 11 Sep 2023
Commented: Adam Danz
on 11 Sep 2023
I want the label color (i.e., of the text) to be a different color than the line color in xline and/or yline.
Is there an easy way to do this without the workaround below?
xline(5, '-', 'Text');
hold on;
xline(5, '-g');
hold off;
2 Comments
VINAYAK LUHA
on 11 Sep 2023
Edited: VINAYAK LUHA
on 11 Sep 2023
Hi Michael,
Instead of plotting the same line twice, you can plot the line once followed by the text as shown below -
xline(5, '-g');
hold on;
text(5, 0, 'Text', 'Color', 'red', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom');
hold off;
Accepted Answer
Dyuman Joshi
on 11 Sep 2023
5 Comments
Adam Danz
on 11 Sep 2023
> The need is to make xlines and ylines...have lower contrast with the plot background color while having the label of the line have high contrast so the viewer can easily read it.
To achieve that, lower the Alpha value of the ConstantLine objects. This won't affect the label.
plot(peaks,'k-')
xline(10,'-k','Default Alpha')
xline([20:10:40], '-k', 'Lower alpha','Alpha',0.2)
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!