how do i keep the format of xticklabels?

1 visualización (últimos 30 días)
Odin Iversen
Odin Iversen el 30 de Mzo. de 2020
Comentada: Star Strider el 31 de Mzo. de 2020
xticks(0:6)
xticklabels(10.^(xticks))
10.^(xticks)
xticklabels
10.^(xticks) returns:
ans =
1 10 100 1000 10000 100000 1000000
but from xticklabels i get:
ans =
7×1 cell array
{'1' }
{'10' }
{'100' }
{'1000' }
{'10000' }
{'100000'}
{'1e+06' }
how do i keep the format so that it keeps the last label as '1000000' and not be converted to '1e+06'.
this is part of a bigger script, wich tests for max an min values of the plots. so manually writing all the labels is not really an optin.
  2 comentarios
Tommy
Tommy el 30 de Mzo. de 2020
Hi! See if
xticks(0:6)
xticklabels(num2str(10.^xticks'))
works.
Odin Iversen
Odin Iversen el 31 de Mzo. de 2020
here you can se italy done the way you said, and the world plot is done without the num2str. stange.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 30 de Mzo. de 2020
Editada: Star Strider el 31 de Mzo. de 2020
Use compose or sprintfc to create the cell array of labels:
figure
plot(0:6, rand(1,7))
xtl = sprintfc('%d',10.^(0:6));
xtl = compose('%d',10.^(0:6));
Ax = gca;
Ax.XTickLabel = xtl;
The ‘xtl’ variable is the same for both, so choose one. (The sprintfc function is undocumented, however everyone has it. Not everyone may have the compose function.)
EDIT — (31 Mar 2020 at 18:00)
Try this:
F = openfig('test.fig');
Kids = F.Children;
Ax = findobj(Kids, 'Type','Axes');
Ax(2).XTickLabel = sprintfc('%d',10.^(0:6));
  2 comentarios
Odin Iversen
Odin Iversen el 31 de Mzo. de 2020
Thank you so much! this worked perfect.
do you know if this has anything similar to xtickformat('%,4.4g')
wich inserts a comma every three digits, so it becomes 1,000,000.
I cant get xtickformat to work in combination with xtick, or xticklabel. it just keeps the original values and intervals for the ticks and labels.
if there is no built in function for this i can make one my self.
Star Strider
Star Strider el 31 de Mzo. de 2020
As always, my pleasure!
The xtickformat function appears to default to exponential notation, regardless of the format descriptor that I provide for it. The sprintfc call (or compose, that will provide the same result) are the only ways I can find to do what you want.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by