How to copy a plot
11 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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
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 Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!