Figure exported from GUI showing wrong position

I wanted to export a figure generated in GUI by clicking a push button. The figure is plotted in axes1. So I wrote axes(handles.axes1) to specify which figure I wanted to export. The code did work. However, the exported figure is in the wrong position. It is showing a random position of the GUI interface. Any help will be highly appreciated!
function export_Callback(hObject, eventdata, handles)
% hObject handle to export (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
[FileName, PathName] = uiputfile('*.eps', 'Save As');
Name = fullfile(PathName, FileName);
print(Name,'-depsc');

댓글 수: 2

Jan
Jan 2017년 3월 21일
편집: Jan 2017년 3월 21일
Please do not confuse the terms: "figure" means the complete window. "GUI" is a "graphical user interface", I guess you mean "GUIDE". Axes contain diagrams, plots, lines or images, but not "figures". "axes(handles.axes1)" specify the axes and implicitly the figure also, which is the parent of the axes. The exported EPS might be located on random positions on the paper, but I cannot imagine, that appears on different positions on the "GUI interface". Why do you specify the axes, when you export the complete figure?
Please explain exactly, what is appearing where. Does "random" mean, that this is not reproducible?
Sorry I didn't explain very clearly. I've attached a zip file containing two images to show what I wanted to do and what I got. I wanted to export the figure plotted on axes1 (highlighted with a red box in GUI.pdf). But the exported EPS shows a different position on the GUI (please see export.eps).

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

 채택된 답변

Jan
Jan 2017년 3월 21일
편집: Jan 2017년 3월 21일

0 개 추천

You can create an EPS file of the figure only. In your export, the 'PaperPosition' was not set appropriately.
If you want to export a single axes only, you have to create a new figure at first and copy the axes to it:
[FileName, PathName] = uiputfile('*.eps', 'Save As');
Name = fullfile(PathName, FileName);
NewFigH = figure;
NewAxesH = copyobj(handles.axes1, NewFigH);
set(NewAxesH, 'Position', get(NewFigH, 'DefaultAxesPosition'))
drawnow;
print(Name, NewFigH, '-depsc');
close(NewFigH);

댓글 수: 1

This code works except that I needed to change the set function slightly to
set(NewAxesH, 'units', 'normalized', 'outerposition', [0 0 1 1]);
Thanks!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2017년 3월 20일

댓글:

2017년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by