How to copy a plot

11 visualizzazioni (ultimi 30 giorni)
Arun
Arun il 20 Dic 2013
Commentato: José-Luis il 20 Dic 2013
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?

Risposta accettata

José-Luis
José-Luis il 20 Dic 2013
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 Commento
José-Luis
José-Luis il 20 Dic 2013
%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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by