Setting Custom Tick Labels in MATLAB
Learn various methods for setting custom labels on the ticks of plots and figures in MATLAB®, including techniques to customize labeling, rotation, and location of ticks.
Published: 27 Sep 2022
Hello, and welcome back to another MATLAB video. Today we're talking about setting custom tick labels on plots in MATLAB. This is a useful skill for any MATLAB user who wants to improve the effectiveness of their data visualizations and apply additional context to plots and figures. These markers can be custom labeled with many data types and can be manipulated to most effectively communicate and visualize data.
The first method for setting custom tick labels is through the XTickLabel function. While we will be discussing the XTickLabel function, the same methods will apply for the yticklabel function. Passing a set of values to the XTickLabel function will label the ticks in order of the given values. This labeling is explicit, or manual, meaning ticks that are not assigned a value will remain blank.
The second method of setting custom tick labels is using dot notation. To use dot notation for tick labels, you must first assign the axes to a handle. This is done by setting the desired handle to gca. gca selects the current set of axes, typically those in the most recently created plot. XTickLabel sets the labels of the current axes. This labeling is implicit, or automatic. This means when a tick is not assigned a label, labeling will begin to repeat from the first assigned tick label.
Tick labels will automatically rotate to avoid overlap when you scale the figure window. This rotation angle can be set manually as well using XTickRotation. XTick returns the locations of the current ticks by setting XTick equal to a set of values. You can change the locations of the ticks as shown here.
In this video, we've discussed how to label the ticks on a plot or figure. Now that we know how to set custom tick labels, we can make more effective visualizations of data. Thanks for watching, and I'll see you in another video.