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

113 vues (au cours des 30 derniers jours)
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;
  7 commentaires
Michael Mazack
Michael Mazack le 11 Sep 2023
Déplacé(e) : Dyuman Joshi le 10 Oct 2024
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 le 11 Sep 2023
Déplacé(e) : Dyuman Joshi le 10 Oct 2024
> 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)

Connectez-vous pour commenter.

Réponse acceptée

Afiq Azaibi
Afiq Azaibi le 4 Oct 2024
Starting in R2024b, you can leverage the LabelColor property on ConstantLine to control the color of the label independently of the line.
x = xline(3, 'r', 'some label');
x.LabelColor = 'k';

Plus de réponses (0)

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by