add text to value of a plot, part 2

2 visualizaciones (últimos 30 días)
alpedhuez
alpedhuez el 26 de Mayo de 2020
Comentada: alpedhuez el 26 de Mayo de 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.

Respuesta aceptada

Star Strider
Star Strider el 26 de Mayo de 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 comentarios
Star Strider
Star Strider el 26 de Mayo de 2020
As always, my pleasure!
I quite definitely agree that it is not an easy problem!
alpedhuez
alpedhuez el 26 de Mayo de 2020
Thnak you.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by