how do i keep the format of xticklabels?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuesta aceptada
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
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Labels and Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!