Inconsistent behavior updating tick labeling
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!