copy axes to clipboard

조회 수: 5 (최근 30일)
Jason
Jason 2014년 11월 3일
댓글: muhammad zulhelmy 2017년 3월 5일
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
muhammad zulhelmy
muhammad zulhelmy 2017년 3월 5일
how can i copy data from axes2, then display to axes3 ??

댓글을 달려면 로그인하십시오.

채택된 답변

Orion
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
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')
Jason
Jason 2014년 11월 4일
Perfect,thankyou again! Jason

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Orion
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');
  댓글 수: 1
Jason
Jason 2014년 11월 3일
편집: Jason 2014년 11월 3일
Hi, thankyou for pointing out the behaviour of plotyy.
In your code, you are finding the handles of the type "Axes". The problem with my application is besides this graph, I also have about 5 other axes components that will obviously also be picked up. How do I limit your findall command to just handles.axes1?
This also explains why when I do a cla , only the one plot clears. How can I clear both plots?. Could I use the following but not use delete, instead cla?
delete(get(handles.axes2,'children'))
Thanks Jason

댓글을 달려면 로그인하십시오.


Orion
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
  댓글 수: 1
Jason
Jason 2014년 11월 3일
Hello. Its still not copying all the data, it now has the 2nd y axis labels and tickmarks. Its also still inside a much larger frame thats also being copied, as per original image at top of this thread?

댓글을 달려면 로그인하십시오.


Orion
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
Orion 2014년 11월 3일
편집: Orion 2014년 11월 3일
it's really up to you, depending on your "coding style".
Personnaly, I like to use setappdata/getappdata, when manipulating handles between multiple figures.
use setappdata in the plot function
then getappdata in the copy function
Jason
Jason 2014년 11월 3일
편집: Jason 2014년 11월 3일
hmmmm. I thought I knew how to use the handles structure to hold variables.
This is my plot:
[AX,H1,H2] = plotyy(A,B,A,C,'plot');
set to handles structure so can use outside this callback
handles.yyaxis=AX;
and to retrieve in a different button callback
hAX=handles.yyaxis;
and I get the error: Reference to non-existent field 'yyaxis'.
Error in Montage>pushbutton21_Callback (line 1719)
hAX=handles.yyaxis; %extract axis from handles structure

댓글을 달려면 로그인하십시오.


Orion
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.

카테고리

Help CenterFile 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!

Translated by