How do I get rid of the scientific notation when using get(gca, 'XTickLabel')?
1 view (last 30 days)
Show older comments
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
Answers (2)
Adam
on 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 Comments
See Also
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!