How do I get rid of the scientific notation when using get(gca, 'XTickLabel')?
1 次查看(过去 30 天)
显示 更早的评论
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
回答(2 个)
Adam
2016-9-1
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!