필터 지우기
필터 지우기

How to plot to two figures simultaneously?

조회 수: 186 (최근 30일)
Hugh Wheaton
Hugh Wheaton 2020년 4월 20일
댓글: Adam Danz 2020년 4월 23일
Here's the idea:
I'm making a live script to be printed and submitted for uni. At one point, I have to plot like 20 figures. It is more convenient to plot all these on a 4x5 subplot to be quickly looked over for mistakes etc., but this isn't good for detail. I was hoping to then simultaneously plot to an invisible figure (say fig(m,"...") in a for loop m=1:20), while also plotting to this subplot, and then printing the resultant figures to (hopefully one multi-page) pdf documents. I'd then attach this to my assignment for further scrutiny.
But nothing seems to do this, and everything I search is saturated with subplot faqs.
Is this reasonable or no? I get atm I could just duplicate the code, but that kinda destroys the whole idea of simultanous coding as it will get really messy, and get quite slow, very quickly.
  댓글 수: 1
Michael Soskind
Michael Soskind 2020년 4월 20일
Hi Hugh,
Seemingly, you would like to plot to two figures, is there a reason you have not tried to do the following?
for m = 1:20 % Going through all 20 plots as above
for i = 1:2
figure(i); hold on; % Selecting which figure to plot to
if i == 1
subplot(4,5,m); % subplot as described above
end
% plot commands that you are using
end
end

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

채택된 답변

Adam Danz
Adam Danz 2020년 4월 20일
편집: Adam Danz 2020년 4월 22일
Create the subplots and then copy each subplot axes to an independent figure at full size.
Here's a demo.
% Create subplot
figure()
sp(1) = subplot(2,2,1);
plot(rand(20,2), '-o')
sp(2) = subplot(2,2,2);
surf(peaks(15))
sp(3) = subplot(2,2,3);
[X,Y] = meshgrid(linspace(-2*pi,2*pi),linspace(0,4*pi));
contour(X,Y,sin(X)+cos(Y))
sp(4) = subplot(2,2,4);
histogram(randn(1,100)+10);
% copy each subplot to an independent figure
for i = 1:numel(sp)
newfig = figure();
axCopy = copyobj(sp(i),newfig);
axCopy.Position = [0.13 0.11 0.775 0.815]; % default fig pos.
end
  댓글 수: 5
Hugh Wheaton
Hugh Wheaton 2020년 4월 23일
how to I do this to maintain the same titles? I can't copy the axis to the subplot as that is, itself, an axis, so I don't really know what to do...
Adam Danz
Adam Danz 2020년 4월 23일
To investigate a handle, you can determine what the handle is:
class(h) % h is the handle.
or just print h in the command window and the first line shows what the handle is (ie, "Line").
Then you can look up "Line properties" in the documentation which defines each property.
If you give titles to each subplot in my example, you'll see that the titles are copied to the figures. "I can't copy the axis to the subplot " -- my example copies an axes to a figure. Are you doing the opposite -- copying an axes to a subplot? If so, there are two ways to do that.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by