Why the 'xticklabels' mismatch the 'xticks' when resizing a figure?

2 visualizaciones (últimos 30 días)
I am plotting a figure using the following code.
x=1:1:9;
y=sin(x);
figure
plot(x,y);
Now I would like to change the 'xticks' from [0,5,10] to {'10','15','20'}.
 
set(gca,'xticklabel',{'10';'15';'20'});
Then if I resize the figure the 'xticklabels' does not match the original ticks. 
How do I resolve this issue?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 23 de En. de 2023
This is expected behavior of MATLAB when no 'xticks' is nominated and the number of assigned 'xticklabels' does not match the number of 'xticks' in a figure. If the number of 'xticklabels' is larger than the 'xticks' number (say n), then the first n 'xticklabels' will show up after rescaling the figure. If the number of 'xticklabels' is smaller than the 'xticks' number (say n), then the n 'xticklabels' will repeatedly show up after rescaling the figure.
The workaround here is to set the 'xticks' before setting the 'xticklabels' using the following code, so that the number of 'xticks' and 'xticklabels' will be the same.
set(gca,'xtick',expectedTicks);
set(gca,'xticklabel',expectedTickLabels);

Más respuestas (0)

Categorías

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

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by