Search code examples
matlabplotlogarithm

cannot plot area with log axis


The code

x=[1e-4 1e-3 1e-2 1e-1];
y=[10 3 100 25];
figure;area(x,y)

returns the following output:

That is correct. But setting the scale of the y axis to logarithmic using

set(gca,'yscale','log');

makes the filling color to disappear:

I cannot understand why. There are no zeros that could mess up the log operation, so why is that?


Solution

  • I get the same problem with R2013a (from what I read the problem disappeared with the new graphics engine). That's because the default BaseValue property of area plots is 0, so we got a problem when working in log scale.

    In order to get rid of it, you can specify the BaseValue property of your area plot to be something different (and larger) than 0, obviously. For example a value of 1 works fine:

    area(x,y,'BaseValue',1)
    

    enter image description here