For those browsing this thread later, the problem was that the plot function was changing the YTick values of the axes objects by itself so that there were 10 ticks in the far left and far right plot, instead of 5. I changed the starting YTick values to 0:10:100 in the far left plot and 0:100:1000 in the far right plot and the problem in those plots resolved itself. The problem with the middle plot was more difficult to hunt down--it was also changing the YTick value on its own, but even when I manually set the YTick value after plotting, the end result was still wildly skewed. I eventually came across the problem here on the forums: I had set the YLim to [0 100000], but 0 is not a valid minimum value for YLim when the axes are logarithmic. After switching YLim to [0.1 100000], the problem resolved right away.
YTickLabels repeating themselves?
13 views (last 30 days)
Show older comments
Christopher Apfelbach
on 24 Aug 2020
Commented: Christopher Apfelbach
on 27 Aug 2020
Hello, everyone,
I came across this unusual...bug? feature? today as I was designing something in the App Designer.
This portion of the program simply takes three double values and plots them into the three axes shown below. The YLim and YTick/YTickLabel values have been set manually in the axes as [0,100] and [0,20,40,60,80,100] for the far left, [0,10^6] and [0,10^1,10^2,10^3,10^4,10^5,10^6] for the middle, and [0,1000] and [0,200,400,600,800,1000] for the far right. When I plot the values, however, not only do the YTickLabels change, they also bizarrely jump from the upper limit of the YLim range back to the lower limit of the YLim range, as can be seen in the far left and far right axes, where the value jumps from 100 up to zero or 1000 up to zero.
As you can see from the mouseover, the values each read correctly in the axes, and the heights of the bar graphs are proportional to where the values would be located if the YTickLabels were displaying correctly. I've read all the documentation I can and searched Answers for hours trying to find out why this might be happening. Any ideas?
Thanks,
Chris

Accepted Answer
Steven Lord
on 25 Aug 2020
Not a bug.
From the table of uiaxes properties in the documentation, specifically the entry for XTickLabel / YTickLabel / ZTickLabel, "Tick labels, specified as a cell array of character vectors, string array, or categorical array. If you do not want tick labels to show, then specify an empty cell array {}. If you do not specify enough labels for all the ticks values, then the labels repeat." The same note appears in the the documentation for axes properties as well so I'll use a plain old axes for this example.
ax = axes;
set(ax, 'YTick', 0:0.25:1)
set(ax, 'YTickLabel', ["1"; "2"])
5 tick locations and 2 tick labels means the first tick gets the first label, the second tick the second label, the third tick the first label again, etc.
More Answers (0)
See Also
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!