How to copy a plot

31 ビュー (過去 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 Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by