How do I get rid of the scientific notation when using get(gca, 'XTickLabel')?

3 Ansichten (letzte 30 Tage)
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

Antworten (2)

Adam
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.

Giovanni Rinaldi
Giovanni Rinaldi am 1 Sep. 2016
Ok I've solved it, I just needed to specify the label also for the values >0 similarly to what I had done for those <0.
new_xticks2 = xticks(~to_change);
labels(~to_change) = arrayfun(@(x)sprintf('%d', x),new_xticks2, 'uniformoutput', false); % Replace the text for labels > 0
I think this does not solve the problem but at least permits to overcome it. Hope will be useful for someone else. Thanks to those who made the effort to find a solution.

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!

Translated by