Non-numeric x-axis labelling?

57 visualizzazioni (ultimi 30 giorni)
Daisy Chapman
Daisy Chapman il 17 Apr 2021
Commentato: Daisy Chapman il 17 Apr 2021
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!

Risposta accettata

Clayton Gotberg
Clayton Gotberg il 17 Apr 2021
Modificato: Clayton Gotberg il 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 Commento
Daisy Chapman
Daisy Chapman il 17 Apr 2021
Hiya! The first method was giving me an error message, but the second one has worked perfectly, thank you!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Oceanography and Hydrology in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by