File Exchange

image thumbnail

xtickinterval, ytickinterval

version 1.0 (5.76 KB) by

XTICKINTERVAL forces tick spacing to a specified interval regardless of axis limits.

1 Download


View License

XTICKINTERVAL and YTICKINTERVAL set the tick spacing of the selected axis to a specified interval. If the axis limits change, either at the user's direction or due to the addition or deletion of plot objects, the ticks are automatically recalculated to fill the new limits, maintaining the specified interval.

By default, the ticks will be placed at integer multiples of the chosen interval. If an optional anchor point is given, the ticks will pass through that anchor point while maintaining the desired interval.

Both the interval and anchor point can be changed by calling XTICKINTERVAL with new values. Additionally, calling XTICKINTERVAL('off') will remove the listener function and restore the axis' tick and ticklabel properties to their original state.

Comments and Ratings (3)

John Barber

John Barber (view profile)

@Eowyn: Unfortunately, it is not possible in general to use a single fixed interval for two different ranges and have the ticks line up. Conversely, if XTICKINTERVAL were to enforce aligned ticks for two ranges, the interval used for the second axis might be fixed at some odd, unhelpful value.

Although it is difficult to see a good solution for the general case of a single interval for multiple ranges, there are some cases where the resulting tick locations would be acceptable. I'll take a look at some methods to handle those cases.

Works, but with plotyy when you ask it to adjust the interval on AX(1), it also places ticks on AX(2). You can still set AX(2) but you'll have ticks from AX(1) as well.

Brian B

This is awesome, thank you so much! One recommendation: It would also be nice to specify the number of yticklabels desired based on the current ylim values vs. just an interval.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video