4

I have a plot in which I'd like many ticks along the x-axis, yet only some of the ticks will have tick labels associated with them. However, I'd like the tick marks for those that have labels to be longer than those that don't.

I know that you can turn the x-axis MinorTicks on, but that won't let you control where those ticks are actually located. For example, if the x-axis signifies days, I want tick marks every 7 days but labels every 28 days.

Moreover, setting the XTickLength only lets you set the length for every tick mark, and not selectively.

What is the best way to control the tick lengths while allowing you to specify exactly where the ticks should be?

2 Answers 2

4

As said by yuk in this SO answer on a similar question about tick labels:

Tick labels are not individual objects. They belong to axes and their properties determined by axes.

What you can do is to remove tick labels and replace them with text objects. In this case you can control the text properties.

I guess the same applies to tick marks, but it is probably trickier.

Another solution could be to overlay your original axis with a second one, as suggested by bdecaf.

1
  • Thanks for the link. I think I'll try doing it by creating a second axis with different tick lengths. Would I use copyobj for that?
    – Josiah
    Feb 9, 2012 at 16:43
1

The R2014b update of the graphics engine introduced the following very simple solution:

h = gca;
h.Box = 'off';
h.XRuler.TickLength = 50;
h.YRuler.TickLength = 30;

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.