- explicitly set the YTickLabel property of the axes (directly or using the yticklabels function, if you're using release R2016b or later) which will change the YTickLabelMode as a side effect or
- change the limits of the axes using ylim so that all the ticks whose labels you want to see are visible
Inconsistent behavior updating tick labeling
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Leo Simon
el 13 de Feb. de 2018
Respondida: Steven Lord
el 13 de Feb. de 2018
In the code below, I'm adding ticks to the Y axis. The first time I do it, YTickLabel updates correctly, adding an additional label. The second time I do it, YTickLabel fails to update properly, keeping the same number of elements when it should add one. I've played around with examples. In this case, the problem appears to be attributable to the fact that I'm adding a new tick below the first tick. If the second line of code is uncommented, then updating happens correctly. Is this a bug? Is there a workaround?
plot(0.5 :0.5:4.6)
%plot(0.0 :0.5:4.6)
YTick = get(gca,'YTick');
set(gca,'YTick',unique([ YTick , 1.9827 ]));
YTick = get(gca,'YTick');
YTickLabel = get(gca,'YTickLabel');
YTick
sprintf('YTick has %i elements', numel(YTick))
YTickLabel'
pause
set(gca,'YTick',unique([ YTick , 0.3519 ]));
YTick = get(gca,'YTick');
YTickLabel = get(gca,'YTickLabel');
YTick
sprintf('YTick has %i elements', numel(YTick))
YTickLabel'
pause
0 comentarios
Respuesta aceptada
Steven Lord
el 13 de Feb. de 2018
If the axes property YTickLabelMode is set to 'auto' (which it is by default) and one of the values of the property YTick is outside the limits of the visible area of the axes returned by ylim, does the YTickLabel property contain a label for that non-visible tick? It does not. If you want that tick to be labeled, you can:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels 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!