How to change the x axis labels of a plot so that they only show integer values
Mostra commenti meno recenti
Id like to make the x axis labels so that it just shows 1,2,3,4,5,6. But id like to make sure this is general so in my code if the user were to input 10 years lets say, the x axis labels would be 1,2,3,4,5,6,7,8,9,10.Thanks!
3 Commenti
Walter Roberson
il 15 Nov 2019
What datatype is the x axes? duration()? Or is it double and you are using datetick() ?
IT Infrastructure Team
il 19 Dic 2022
XTick not XTicks works in my case
Risposte (2)
Walter Roberson
il 15 Nov 2019
ax = gca;
ax.Xticks = unique( round(ax.XTicks) );
2 Commenti
AStar
il 15 Nov 2019
Walter Roberson
il 12 Mar 2020
Modificato: Walter Roberson
il 12 Mar 2020
ax is a variable assigned the result of gca . gca is a function that returns a handle to the current axes. So ax will be assigned a handle to the current axes.
ax = gca;
ax.XTick = unique( round(ax.XTick) );
S. Cho
il 12 Mar 2020
curtick = get(gca, 'xTick');
xticks(unique(round(curtick)));
2 Commenti
Walter Roberson
il 12 Mar 2020
Note: this requires R2016b or later. For earlier releases, especially before R2015b, it would look like,
curtick = get(gca, 'XTick');
set(gca, 'XTick', unique(round(curtick)))
Housam
il 3 Apr 2022
ax.YAxis(2).TickLabels= unique( round(ax.YAxis(2).TickValues) )
Categorie
Scopri di più su Axis Labels in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!