Force exponential format of ticks LIKE MATLAB does it automatically

user1812071 picture user1812071 · Nov 10, 2012 · Viewed 10.3k times · Source

I have two plots. In the first plot the values for the y-axis go up to 30000. Therefor, Matlab is labeling the axis instead of '30000' with '3' and the 'x10^4' ABOVE the plot. In the second plot the y-values just go til 10000. Due to the fact that this value is too low to automatically switch to exponential format it really prints '10000'.

I would like to know if there is a way to force the exponential formatting. This will result in THE SAME FORMAT as Matlab does it automatically. I am asking this because I have seen solutions where you can make Matlab print '10^3' directly as Y-label, but I just want to have it show '1' as Label and the 'x10^3' above the plot.

The following image shows to different plots merged together just for the purpose of clarifying my question. In the left half of the image you can see what Matlab does if I am using values > 10000. And that's the kind of format I want to get for the axis shown in the second half if the image below.

Exponential formatting vs. regular

Answer

Adiel picture Adiel · Jan 22, 2018

I just get here because I need something similar, and I know that now there is a solution for that. Perhaps from R2015 and newer, you can set the exponent excatly with:

ax.YAxis.Exponent = 3  % 3 is for example

Or, if you want the full numbers:

ax.YAxis.Exponent = 0

While ax is the axis handle.