Non-numeric x-axis labelling?

56 views (last 30 days)
I have three data sets with the same number of points, that each represent the period from high tide to low tide, with a data set corresponding to data from a given day. The data is aligned so that high tide for all three is the same data point, and low tide is the same data point, but these occur at different times of day. 30 data points covers 1 hour.
I want to label the x-axis as HT, HT+1 (to denote 1 hour after high tide), HT+2 (to denote 2 hours after high tide) etc but have no idea how to do this, and can't succinctly describe what I'm trying to do so I'm struggling to find information when I search. Does anyone have any guidance or knowledge about how to do this?
Thanks!

Accepted Answer

Clayton Gotberg
Clayton Gotberg on 17 Apr 2021
Edited: Clayton Gotberg on 17 Apr 2021
Use xticklabels to add labels to the x-axis of a plot.
plot(<plot data>)
x_label_locations = [0 1 2]
x_labels = {'HT','HT+1','HT+2'}
xticks(x_label_locations)
xticklabels(x_labels)
If you prefer, you can also assign these directly to the axes properties:
plot(<plot data>)
x_label_locations = [0 1 2]
x_labels = {'HT','HT+1','HT+2'}
ax = gca; % Get current axes being plotted to
ax.XTick = x_label_locations;
Ax.XTickLabel = x_labels;
  1 Comment
Daisy Chapman
Daisy Chapman on 17 Apr 2021
Hiya! The first method was giving me an error message, but the second one has worked perfectly, thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!