Can I change the color of the label in xline / yline to be different from the color of the line?
Afficher commentaires plus anciens
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
Dyuman Joshi
le 11 Sep 2023
Déplacé(e) : Dyuman Joshi
le 10 Oct 2024
VINAYAK LUHA
le 11 Sep 2023
Modifié(e) : VINAYAK LUHA
le 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;
Michael Mazack
le 11 Sep 2023
Déplacé(e) : Dyuman Joshi
le 10 Oct 2024
Walter Roberson
le 11 Sep 2023
Déplacé(e) : Dyuman Joshi
le 10 Oct 2024
The next release of MATLAB is expected to be within the next two weeks. This proposal for xline and yline text color will definitely not make it into that release.
Steven Lord
le 11 Sep 2023
Déplacé(e) : Dyuman Joshi
le 10 Oct 2024
But it does sound like a reasonable enhancement request to file with Technical Support directly using this link. When you submit that enhancement request, please include some information about how you'd use this functionality in your actual work. Those types of user stories are very valuable when prioritizing work or making sure we don't design our tree swing in such a way that makes it useless for your needs.
For example, is the only property of the label that you need to change independent of the line with which it's associated the color? Or are there other properties that would satisfy your needs?
Michael Mazack
le 11 Sep 2023
Déplacé(e) : Dyuman Joshi
le 10 Oct 2024
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)
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


