add text to value of a plot, part 2

2 vues (au cours des 30 derniers jours)
alpedhuez
alpedhuez le 26 Mai 2020
Commenté : alpedhuez le 26 Mai 2020
I have a plot with x axis takes the value January 1, January 2, .... and y axis takes the temperature of that day. In the x axis, I want to have these days and add a text "day" to these values so that they will be "Day 1 (January 1)","Day 2 (January 2)", "Day 3 (January 3)",... I did not find a relevant post on the Internet.

Réponse acceptée

Star Strider
Star Strider le 26 Mai 2020
That needs a different approach.
Try this:
x = 1:10
y = rand(1,10);
figure
plot(x, y)
xt = get(gca, 'XTick');
xtklbl = sprintfc('Day %d (January %d)', [xt; xt]');
set(gca, 'Xtick',xt, 'XTickLabel',xtklbl, 'XTickLabelRotation',30)
You can also use the compose function in place of sprintfc (undocumented).
  9 commentaires
Star Strider
Star Strider le 26 Mai 2020
As always, my pleasure!
I quite definitely agree that it is not an easy problem!
alpedhuez
alpedhuez le 26 Mai 2020
Thnak you.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by