copy axes to clipboard
6 views (last 30 days)
Show older comments
Hello. I am wanting top copy several plots from my gui. One plot is on a uipanel and the other is a graph on an axes component. I have tried the axes component first using :
currAxes = handles.axes1
newFig = figure('visible','off');
newHandle = copyobj(currAxes,newFig);
print(newFig,'-dmeta');
delete(newFig);
It sort of works. The issues are: 1: It only copies one of the yaxis (the plot on axes1 is a plot with two yaxis, using plotyy). 2: It copies with a large box around it.
The attached image shows the result of the copy, and the actual graph I want copied.
Am I using the correct method? Thanks Jason
1 Comment
Accepted Answer
Orion
on 3 Nov 2014
if you're using GUIDE, don't forget to get and restore the handles structure with guidata
function Your_plot_Pushbutton(hObject, eventdata, handles)
% code,code,code
[AX,H1,H2] = plotyy(A,B,A,C,'plot');
handles.yyaxis=AX;
% save the changes to the structure
guidata(hObject,handles)
and then you can retrieve it in the copy function
function Your_copy_Pushbutton(hObject, eventdata, handles)
hAX=handles.yyaxis;
14 Comments
Orion
on 4 Nov 2014
So, gook luck.
And I get one last Idea.
You can try the same callback as in the edit menu of the figure, which seem to work on your machine. It works for me.
Replace the call to print with editmenufcn.
%%metacopy
% print(newFig,'-dmeta');
editmenufcn(newFig,'EditCopyFigure')
More Answers (4)
Orion
on 3 Nov 2014
Hi,
Actually, plotyy creates 2 superimposed axes objects (see the doc about the differents outputs arguments).
So you need to copy all the axes in the new fig.
with your code
currAxes = handles.axes1
newFig = figure('visible','off');
newHandle = copyobj(currAxes,newFig);
print(newFig,'-dmeta');
you are only copying one axe, so it's logical that you miss the second.
you may need to do something like:
AllAxes = findall(gcf,'Type','Axes') % get all the axes
newFig = figure('visible','off');
newHandle = copyobj(AllAxes,newFig); % copy all axes in the figure to print
print(newFig,'-dmeta');
Orion
on 3 Nov 2014
In the prototype of plotyy
[AX,H1,H2] = plotyy(...)
AX is a vector containing the handles of the 2 axes objects created by plotyy.
so when you stock your data, you could do
handles.axesplotyy_1 = AX(1);
handles.axesplotyy_2 = AX(2);
and then use these handles the way you need.
AxesToCopy = [handles.axesplotyy_1 handles.axesplotyy_2];
newFig = figure('visible','off');
newHandle = copyobj(AxesToCopy,newFig);
then do the same to delete/cla
delete([handles.axesplotyy_1 handles.axesplotyy_2]) % destroy both axes
Orion
on 3 Nov 2014
Edited: Orion
on 3 Nov 2014
my bad, i went a little fast in my explanation.
So, with an example
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
figure % new figure
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
newFig = figure('visible','on');
% copy the axes in the 2nd figure
hcop = copyobj(hAx,newFig);
axes(hcop(2)); % to put the second axe (transparent) in first plan
% resize if needed the dimensions of the axes to fill screen
% with the value you want (Normalized)
set(findall(newFig,'Type','Axes'),'Position',[ 0.100 0.1100 0.8 0.8150]);
% metacopy
print(newFig,'-dmeta');
3 Comments
Orion
on 3 Nov 2014
Matlab is clear,
Undefined function or variable 'hAx'.
when you do
hcop = copyobj(hAx,newFig);
you are using hAx, but you created the variable with hAX : X instead of x.
hourra for the end of the day.
0 Comments
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!