필터 지우기
필터 지우기

How can I prevent scientific notation on my axes in MATLAB R2015a and earlier releases?

조회 수: 28 (최근 30일)
Is there a way to control the output of plots so that they don't automatically display in scientific notation?
I need something that enables me to control how the tick labels are displayed on the axes. That way, when I zoom in or out, I can force the label format to non-scientific.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 10월 6일
편집: MathWorks Support Team 2020년 10월 7일
If you are using MATLAB R2015b or a later release, please refer to the following MATLAB Answers post: 
In MATLAB R2015a and earlier releases, you can use the following method.
1. Plot your data.
>> x = rand(100, 1);
>> y = 1e-3*x;
>> plot(x, y)
2. Get a handle to the current figure and axes:
>> hFig = gcf
>> hAxes = gca
3. Define a function that reformats the tick labels as follows:
function reformatTickLabels(hAxes)
XTickLabel = get(hAxes,'XTick');
set(hAxes,'XTickLabel',num2str(XTickLabel'))
YTickLabel = get(hAxes,'YTick');
set(hAxes,'YTickLabel',num2str(YTickLabel'))
end
where "hAxes" is the axes handle.
4.  Call this function to format your tick labels, before zooming.
>> reformatTickLabels(hAxes);
5. Get the handle to the zoom mode object of the figure:
>> z = zoom(hFig);
7. Set the "ActionPostCallback" function on the zoom handle to the function "reformatTickLabels". This means that after you perform a zooming action, this callback function will be called and executed. In this way, the tick labels will stay in non-scientific format even after zoom events.
set(z,'ActionPostCallback',@zoomReformatLabels)
where "zoomReformatLabels" is defined as
function zoomReformatLabels(obj,evd)
reformatTickLabels(evd.Axes)
end
where "obj" is the handle to the figure that has been clicked on and "evd" is the object containing the structure of event data.
More information on the zoom callback functions can be found here:
https://www.mathworks.com/help/releases/R2020a/matlab/ref/zoom.html
Note: This link is from MATLAB R2020a documentation. Some things might not be applicable for MATLAB R2015a as expected.

추가 답변 (1개)

Steven Lord
Steven Lord 2018년 1월 5일
편집: MathWorks Support Team 2021년 12월 30일
Starting in release R2015b you can take advantage of rulers to customize the appearance of the axes. For example:
% Create a plot
x = linspace(0,5,1000);
y = 100*exp(x).*sin(20*x);
h = plot(x,y);
% Obtain the ruler for the Y axis of the axes
ax = ancestor(h, 'axes');
r = ax.YAxis;
% Change the format of the tick labels and remove the scientific notation
r.TickLabelFormat = '%g mm';
r.Exponent = 0;
If you were to zoom on and zoom into the plot, you will see that the Y axis labels keep the same format. If you change the tick locations the labels of the ticks keep the same format.
ax.YTick = -15000:3750:15000;
See the links in the documentation of the XAxis, YAxis, and ZAxis properties of the axes for more information about what you can do with rulers.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by