필터 지우기
필터 지우기

How to transfer axes from GUI to figure and save as PDF

조회 수: 5 (최근 30일)
David C
David C 2013년 3월 22일
I have a GUI (handle = main) that allows the user to select some data and then plots it on the axis built into the GUI (handle = axes1)
After the plot is generated, I'm trying to save the image as a PDF, but I'm running into the following issues:
1) copyobj(handles.axes1,h_fig) doesn't keep both primary and secondary axes, and upon closing h_fig, the secondary axis from the GUI disappears!
2) copyobj(get(main,'children'),h_fig) gets EVERYTHING form the GUI including the push buttons, listboxes, etc which I don't want. Even this method, the positioning of the legend isn't copied over correctly.
3) i tried to use the export_fig script submission from Oliver Wood and it has the same issue. I tried both export_fig, as well as isolate_axes functions, both only keep the primary axis info.
Am i doing something wrong? is the secondary axes hidden when it gets copied? and once copied, does the visibility get set to invisible on the original GUI axes?
Any help is greatly appreciated!

답변 (2개)

Mahdi
Mahdi 2013년 3월 25일
I had this problem a while ago. I couldn't figure out how to solve it.
I figured the best way was to open up a new figure (In the callback function, open a new figure, say figure 1 - type figure(1)), then plot the same data that you want, save figure 1, then close figure(1). This is definitely inefficient though, but I haven't found a different way.

David C
David C 2013년 3월 25일
Mahdi,
I figured out the solution.
First you have to find all the axes on the GUI that are NOT legends with the command:
H1 = findobj(maingui,'type','axes','-not','tag',legend');
then get the legend
L1 = findobj(maingui,'tag','legend');
Then use copyobj to copy those handles from the GUI to the new figure, and finally save the figure.
After debugging, I realized that if you use plotyy to make plots on a axes, the primary and secondary axis have different handles (something I should have realized since that is one of the ways to call the plotyy function)
Anyway, after finding all the objects and copying them over, it was a matter of setting their 'location' parameter and fitting them on a 8.5x11 paper which took some finessing.
I think this is still pretty inefficient cause my code is almost half a page long, but it gets the job done for now.
  댓글 수: 1
Oliver Woodford
Oliver Woodford 2013년 6월 19일
David: If you call export_fig([h1 h2], 'test.jpg'), where h1 and h2 are the two axes handles returned by plotyy, does that work?

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

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by