How to label a stem plot??

14 vues (au cours des 30 derniers jours)
Milosha Britto Nordbø
Milosha Britto Nordbø le 3 Mai 2020
Commenté : Star Strider le 16 Mai 2020
How can i add labels to the stem diagram?? I have attached a pic to be specific where i require the labels.

Réponse acceptée

Star Strider
Star Strider le 3 Mai 2020
Try this:
Year = 1995:2020;
Group = randi([2000 11000], size(Year));
figure
stem(Year, Group, 'filled')
lblc = sprintfc('%d',Group);
text(Year, Group+100, lblc, 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
Make appropriate changes to the text and sprintfc calls to display the result you want. (The sprintfc function is undocumented, however uses the sprintf syntax. You can also use the compose function to produce a cell array of labels.)
  2 commentaires
Milosha Britto Nordbø
Milosha Britto Nordbø le 16 Mai 2020
Thank you. I made one change and it worked (see below the change in bold).
lblc = sprintfc('%d',Group1);
Thank you once again.
Star Strider
Star Strider le 16 Mai 2020
As always, my pleasure!
I somehow missed the ‘1’. My apologies!

Connectez-vous pour commenter.

Plus de réponses (1)

Milosha Britto Nordbø
Milosha Britto Nordbø le 16 Mai 2020
No problem, at least I understood it. If you had the '1' then I wold never understand the logic behind it.
  1 commentaire
Star Strider
Star Strider le 16 Mai 2020
Noted!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by