Search code examples
matlabmatlab-figureaxis-labels

Rescaling Y axis in a plot


I am trying to adjust the y axis and change it to be from [0 2.5] and to show that it has to be multiplied by a factor of 1000.

Obviously setting the limit with ylim=([0 25]) doesn't work and I can't find a way to do it.

image

Using to plot:

AveTime = 1.0e+03 * [0.0020, 0.0291, 0.1279, 0.3061, 2.0599];
STDtime = [0.0519, 0.0117, 0.0166, 0.0071, 0.0165];
errorbar([10,25,50,75,100], AveTime, STDtime);

Solution

  • I believe this is what you need, it should work for Matlab versions >= 2014b:

    ax = gca;
    ax.YAxis.Exponent = 3;
    

    Here's a code example:

    clear;
    close all;
    clc;
    
    x=1:10:1000;
    y=3*x;
    plot(x,y);
    ax = gca;
    ax.YAxis.Exponent = 3;
    

    And the plot:

    enter image description here