How to copy a plot

조회 수: 13 (최근 30일)
Arun
Arun 2013년 12월 20일
댓글: José-Luis 2013년 12월 20일
How can I copy a plot into a new figure. Then on the new figure plot a vector on a second y axis. I have tried to use the copyobj and plotyy. However I may been using incorrect syntax.
Update
The original figure is produced by a function. What would be the syntax in this case?

채택된 답변

José-Luis
José-Luis 2013년 12월 20일
fH(1) = figure(1);
fH(2) = figure(2);
fH(3) = figure(3);
figure(fH(1));
lH = plot(rand(10,2));
aH = ancestor(lH(1),'axes');
figure(fH(2));
aH(2) = axes;
copyobj(lH(1),aH(2)); %copy line to axes
copyobj(aH(1),fH(3)); %copy axes to figure
  댓글 수: 1
José-Luis
José-Luis 2013년 12월 20일
%Some figure you know nothing about
plot(rand(10,2)); %click it to make it the active figure
%Find its handle
aH = gca;
fH = ancestor(aH,'fig');
fH(2) = figure(2); %Figure you want to copy the stuff to
%Copy axes or see my previous code to copy lines, store its handle
aH(2) = copyobj(aH,fH(2));
%create new axes
aH(3) = axes('Position',get(aH(2),'Position'));
linkaxes(aH(2:3),'x');
%Plot your new stuff
plot(1:10);
%Making them look nice
set(aH(3),'YAxisLocation','right','Color','none');
set(aH(2:3),'box','off');
Please accept an answer if it helps you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by