Non-numeric x-axis labelling?

60 vues (au cours des 30 derniers jours)
Daisy Chapman
Daisy Chapman le 17 Avr 2021
Commenté : Daisy Chapman le 17 Avr 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!

Réponse acceptée

Clayton Gotberg
Clayton Gotberg le 17 Avr 2021
Modifié(e) : Clayton Gotberg le 17 Avr 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 commentaire
Daisy Chapman
Daisy Chapman le 17 Avr 2021
Hiya! The first method was giving me an error message, but the second one has worked perfectly, thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Oceanography and Hydrology dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by