copy axes to clipboard
조회 수: 5 (최근 30일)
이전 댓글 표시
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
채택된 답변
Orion
2014년 11월 3일
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
Orion
2014년 11월 4일
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')
추가 답변 (4개)
Orion
2014년 11월 3일
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
2014년 11월 3일
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
2014년 11월 3일
편집: Orion
2014년 11월 3일
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
Orion
2014년 11월 3일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

