View License

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

» Watch video

Highlights from
xtickinterval, ytickinterval

4.0 | 2 ratings Rate this file 3 Downloads (last 30 days) File Size: 5.76 KB File ID: #30674 Version: 1.0

xtickinterval, ytickinterval


John Barber (view profile)


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

| Watch this File

File Information

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.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
31 May 2014 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.

Comment only
19 Jun 2013 Eowyn Baughman

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.

09 Oct 2011 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.

Contact us