semilog plots with hold on

Matthias Pospiech picture Matthias Pospiech · Feb 28, 2012 · Viewed 34.1k times · Source

If I try to plot multiple plots with a logarithmic axis, the log scale is disabled. If I remove the hold on the log scale is enabled, but I can only plot a single plot.

figure(1); clf
x = linspace(0,1,100);
y = exp(-x);

hold on;
semilogy(x, y);
semilogy(x, 2*y);
hold off;

Why?, How can I create multiple log scale plots?

Answer

Johan Lundberg picture Johan Lundberg · Feb 28, 2012

Your code works already in octave (and I don't have matlab at this computer), but I think the problem is that you do hold on before the first plot, hence preventing the initial axis to be created. try this:

figure(1); clf
x = linspace(0,1,100);
y = exp(-x);

semilogy(x, y);
hold on;
semilogy(x, 2*y);
hold off;