How do I get rid of the scientific notation when using get(gca, 'XTickLabel')?
조회 수: 2 (최근 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!