From the help for subplot
:
If a subplot specification causes a new axes to overlap an
existing axes, the existing axes is deleted - unless the position
of the new and existing axes are identical.
Your code is doing this, though you may not realize it. You call subplot(151)
, which places an axis in the default location and then you position it manually. Because you have manually positioned the first axis, calling subplot(152)
is the same as calling subplot(151)
and the new axis ends up on top of the first one causing the latter to be deleted. And so on, until you move axes away from the the area where the default axis is placed.
There are several ways around this. You can create all of your subplots and then go back and position them. You can create your subplots starting from the right of your figure (subplot(155)
) and move left. Or you can create the subplots in the desired positions directly via:
subplot('Position',[0.15 0.15 0.15 0.75]);
subplot('Position',[0.31 0.35 0.15 0.55]);
subplot('Position',[0.46 0.35 0.15 0.55]);
subplot('Position',[0.61 0.35 0.15 0.55]);
subplot('Position',[0.76 0.35 0.15 0.55]);
You can have these return handles if you need to plot to these axes separately at a later time via plot(AX,...)
or subplot(AX); plot(...)
, where AX
is an axis handle.
Also note that the help for subplot
contains special comments for the subplot(151)
style, particularly:
This syntax does not return a handle, so it is an error to specify a return argument.
I get a handle back myself, but I don't know if it's to be trusted. Still, even changing the style to subplot(1,5,1)
the issue of only showing the last three persists.