20

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?

Memming
  • 1,731
  • 13
  • 25
Matthias Pospiech
  • 3,130
  • 18
  • 55
  • 76

1 Answers1

35

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;
Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97