How do I get rid of the scientific notation when using get(gca, 'XTickLabel')?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, as per title I would like change the labels of my x axis in order to avoid the scientific notation. I have already seen that this is a common problem usually solved with set(gca, 'XTickLabel', whatever). Unfortunately in my script I need to first get the property of the current axis, in order to introduce a variation for the values < 0, and only after set it to its value. Is there a way of obtaining this? I attach my script so that you can see what I mean. Many thanks
xticks = get(gca, 'xtick'); % Get current ticks
labels = get(gca, 'XTickLabel'); % Get current labels; Unfortunately if it is 2000, 3000, etc. it gets only 2,3,etc. Here my problem
if ischar(labels); labels = cellstr(labels); end % Convert labels values into strings
to_change = xticks < 0; % Change labels of values < 0; this is necessary for the plot
new_xticks = abs(xticks(to_change) / scale);
labels(to_change) = arrayfun(@(x)sprintf('%0.2f', x),new_xticks, 'uniformoutput', false); % Replace the text for labels < 0
set(gca, 'xtick', xticks, 'xticklabel', labels) % Update the tick locations and the labels
1 Kommentar
Antworten (2)
Adam
am 1 Sep. 2016
If you are using R2015b or later,
hAxes.XAxis.Exponent = 0;
should ensure that you do not have scientific notation, where 'hAxes' is the handle to your axes.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!