How to get Subplot without losing data

조회 수: 32 (최근 30일)
Brave A
Brave A 2021년 3월 3일
댓글: Walter Roberson 2021년 3월 3일
Hi,
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!,

답변 (1개)

Walter Roberson
Walter Roberson 2021년 3월 3일
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:
  • 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.
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.
  댓글 수: 2
Brave A
Brave A 2021년 3월 3일
then what is the best way to show all 3 figures with details?
Walter Roberson
Walter Roberson 2021년 3월 3일
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
axes(ax(3));
stairs(randn(1,40));

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by