Can I change the color of the label in xline / yline to be different from the color of the line?

63 次查看(过去 30 天)
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 个评论
VINAYAK LUHA
VINAYAK LUHA 2023-9-11
编辑:VINAYAK LUHA 2023-9-11
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;

请先登录,再进行评论。

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-9-11
Unfortunately, No, there is no property "Label color" for xline and yline functions (Constant Line Annotation) which can be modified.
Also, you don't need to use hold for xline() and yline().
  5 个评论
Michael Mazack
Michael Mazack 2023-9-11
Thanks, Steven -- very helpful suggestion.
The need is to make xlines and ylines -- which may obscure the data and blank space -- 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.
I have submitted an enhancement request at the link you provided with more user story detail. Thank you.
Adam Danz
Adam Danz 2023-9-11
> 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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by