Behavior of subplot
John W. Eaton
jwe at octave.org
Mon Feb 9 20:59:37 CST 2009
On 9-Feb-2009, Michael D. Godfrey wrote:
| I used an old function that contained subplot calls
| with the current development Octave. It took a while
| to recover the old behavior. The example below shows
| what seems to me counter intuitive behavior:
|
| hold off
| x = [0:.1:10];
| sx = sin(x);
| cx = cos(x);
| for k=1:3
| axis([1,10,-1,1]);
| subplot(2,3,k);
| plot(x, sx);
| axis([1,20,-1,1]);
| subplot(2,3,3+k);
| plot(x, 10*sx);
| endfor;
|
| ====================================
| For me the resulting six plots have the following properties:
|
| Plots 1, 2, 3 (top row) xscale: 1:20, yscale: -1:+1
| Plots 4 and 5: xscale:1:10, yscale: -1:+1
| Plot 6: xscale: 0:10; yscale: -10:+10
| ======================================
|
| For me, predictable results could only be obtained by using
| the sequence:
|
| subplot()
| hold on
| axis()
| plot()
|
| Also, I noticed that the behavior if the commands were entered
| at the Octave prompt is different from the result of executing
| them from a script. What happens is that subsequent subplot
| commands "overwrite" the displayed result of a previous command.
In the old days, Octave followed the gnuplot way of doing plotting, so
that a call to axis (for example) affected subsequent plots. But now
we are doing things in the Matlab way, so calls to axis affect the
current plot. So I suspect you just need to move the axis commands
afte the plot commands, like this:
hold off
x = [0:.1:10];
sx = sin(x);
cx = cos(x);
for k=1:3
subplot(2,3,k);
plot(x, sx);
axis([1,10,-1,1]);
subplot(2,3,3+k);
plot(x, 10*sx);
axis([1,20,-1,1]);
endfor
Except for possible spacing problems, does that produce the plot you
expect?
jwe
More information about the Bug-octave
mailing list