Why do the labels of the last tick marks disappear when I set axes location to origin?

88 views (last 30 days)
Hesham Buhedma
Hesham Buhedma on 6 May 2017
Answered: J. Scott Berg on 2 Jun 2020
The data I'm plotting requires both axes to be at the origin for easy interpretation. For some reason when axes location is set at origin, the labels of the final tick marks disappear. I have no idea how to fix this and I'd rather not resort to moving the axes manually or typing the labels in Illustrator.
Here is the lines of code causing the problem:
ax.XAxisLocation = 'origin'
ax.YAxisLocation = 'origin'
Has anyone encountered this problem before?
  8 Comments

Sign in to comment.

Answers (1)

J. Scott Berg
J. Scott Berg on 2 Jun 2020
If hAx is the axes object, then hAx.YAxis is the NumericRuler object for the Y axis. It has an undocumented property TickLabelChild, which has a String property with the actual strings that are rendered. If you look at hAx.YAxis.TickLabelChild.String, you will find that the label is missing even though it appears in hAx.YAxis.TickLabels. So, you can set up hAx.YAxis.TickLabels how you like it, then do
set(ax.YAxis.TickLabelChild,'String',ax.YAxis.TickLabels)
to have them rendered properly. Do this after you have set the axis limits, tics, etc. If you subsequently do anything that would change axis limits, number of tick labels, etc., first do
set(ax.YAxis.TickLabelChild,'StringMode','auto')
otherwise it may be unhappy about the number of stings in the TickLabelChild not matching up with the number of ticks in the NumericRuler parent.
None of this appears to be documented, so it may not work in your version.

Community Treasure Hunt

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

Start Hunting!