Setting different tick lengths

2019-07-04 06:25发布

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条回答
forever°为你锁心
2楼-- · 2019-07-04 06:47

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-04 06:58

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

查看更多
登录 后发表回答