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

46 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 Oct 2020
Edited: MathWorks Support Team on 7 Oct 2020
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');
YTickLabel = get(hAxes,'YTick');
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.
where "zoomReformatLabels" is defined as
function zoomReformatLabels(obj,evd)
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:
Note: This link is from MATLAB R2020a documentation. Some things might not be applicable for MATLAB R2015a as expected.

More Answers (2)

Econstudent on 11 Apr 2017
Edited: Econstudent on 11 Apr 2017
It has been a while, but in case someone is looking into this, here is a solution.
1. Command your plot; 2. Use this:
Ytick = strsplit(num2str(get(gca, 'Ytick')));
This command gets the 'Ytick' values from the gca of your open plot. Then, it turns that into a single string, before splitting it into an array (which is exactly what the plot's gca uses to label the ticks).
3. The next command just makes an adjustment to the plot's gca using the new string array:
set('YtickLabel', Ytick);
The advantage here is that you avoid the use of additional objects. If you do not want to make a function (say, it's a very punctuated use), it works without crowding your workspace.
Steven Lord
Steven Lord on 5 Jan 2018
The code in section 3 has an error. The first input to set must be a handle to the Handle Graphics object (in this case an axes) whose properties you want to change. If you only have the handle to your area plot, use ancestor to get the 'axes' ancestor of the plot.

Sign in to comment.

Steven Lord
Steven Lord on 5 Jan 2018
Edited: MathWorks Support Team on 30 Dec 2021
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.




Community Treasure Hunt

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

Start Hunting!