- you specified a subplot that spans multiple sections and part was already occupied. You can identify these calls because the third location parameter is a vector, such as subplot(3,2,[3 6])
- you specified a subplot that does not span multiple locations, but it intersects an earlier subplot that did span
- you used subplot when you have an existing plot that did not use subplot
- you used subplot to create a different subplot earlier and adjusted the Position property to make it a different size or position, and now you subplot specifying a location that intersects the expanded location
- you used subplot earlier to define a the location of this axes, and then you set the Position property to customize the location, and now you call subplot to try to return to that logical tile. subplot will notice that the axes is not where it expects and will delete it.
How to get Subplot without losing data
32 views (last 30 days)
Show older comments
Brave A on 3 Mar 2021
Commented: Walter Roberson on 3 Mar 2021
I am trying to plot 3 subbplot, but the problem is the sublplot delete some parts from figures like legend and some details for axis. How to avoid that?
thanks in advance!,
subplot() checks the location information you provide, and figures out what part of the figure that implies. It then checks to see if there is any existing axes that intersects the calculated figure position, and if there is then it deletes the axes unless the axes is exactly the same position as what it just calculated.
Because of the this, subplot can delete existing plots under a couple of circumstances:
subplot is not a logical layout to say "I want an array of plots that I am going to customize whenever I feel like it." subplot() effectively manages particular sections of the figure, and has no way of marking an axes as "originally" being from a particular subplot. An existing axes it overlays is either exactly in the default position and is used, or else the existing axes is deleted.
You can subplot() three times and record the axes handles each time. Then after that you can change the Position properties of the handles as you want, but each time refer to the axes handle instead of calling subplot() to locate the section again.
for K = 1 : 3; ax(K) = subplot(3,1,K); end
%once the axes are created
%you can name the axes when you plot, and you can change the size
plot(ax(1), rand(1,10)); title(ax(1),'1');
ax(1).Position = ax(1).Position .* [1 1 1.2 1.2]; %make it bigger
%you can hold the axes and plot more
imagesc(ax(2), rand(32,40)); hold(ax(2), 'on'); plot(ax(2), rand(1,40)*30, 'r'); hold(ax(2),'off');
%you can make the axes current and use it
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!