Controlling current axes within programmatic UI (GUI layout toolbox)

조회 수: 2 (최근 30일)
D. Plotnick
D. Plotnick 2016년 3월 30일
댓글: John BG 2017년 10월 19일
I am currently building a programmatic UI using the GUI layout toolbox (GLT), and I am having difficulty convincing Matlab to use the axes that I want for plotting purposes. I am including a MWE below (note, it requires the GLT, although I do not believe that is the source of the issue).
The issue is that as written below the scatter3 plots in a new figure window that it opens itself, not the UI axes.
function gui = guiTest
gui = struct();
% Initialize Window
scrsz = get(groot,'ScreenSize');
gui.Window = figure( ...
'Name', 'A Test Window', ...
'NumberTitle', 'off', ...
'MenuBar', 'none', ...
'Toolbar', 'none', ...
'HandleVisibility', 'off',...
'OuterPosition', [3*scrsz(4)/4 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2]);
% Create Main Layout
mainLayout = uiextras.HBoxFlex(...
'Parent',gui.Window,...
'Spacing',3);
% Left Side Control Panel
controlPanel = uiextras.BoxPanel(...
'Parent',mainLayout,...
'Title','Controls go here');
% Right Side Plotting
gui.ViewPanel = uiextras.BoxPanel(...
'Parent', mainLayout,...
'Title','Axes Panel Name');
% Relative sizes of main layout sections
set(mainLayout, 'Sizes', [-1 -2]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Right Side Plotting %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gui.ViewAxes = axes(...
'Parent',gui.ViewPanel);
X = rand(100,1); Y = rand(100,1); Z = rand(100,1);
axes(gui.ViewAxes);
scatter3(X,Y,Z); axis equal;
end
Note that I have solved the issue my changing the last line of the above to:
scatter3(X,Y,Z,'Parent',gui.ViewAxes); axis(gui.ViewAxes, 'equal');
Which may just be how I have to work from now on. However, my question is why the command to switch axes using axes(gui.ViewAxes) does not actually seem to make the active figure/axes pair remain as the current axes. This is why gca is a dangerous command to use, but I would like to understand if there is some UI handle shenanigans that I am simply not understanding.
Please, no suggestions that I go back to GUIDE.
Thanks in advance!

채택된 답변

Robert
Robert 2016년 3월 30일
gca calls gcf and checks the 'CurrentAxis' property of the result. Because you turned you figure's 'HandleVisibility' to 'off', gcf cannot find it and creates a new figure instead.
  댓글 수: 2
D. Plotnick
D. Plotnick 2016년 3월 30일
편집: D. Plotnick 2016년 3월 30일
facepalm. Yes...yes I did. Thanks!
I also just posted using a similar MWE regarding the rotate3d tool not refreshing the plot when used. Switching the 'HandleVisibility' to 'on' does not seem to solve that problem.
John BG
John BG 2017년 10월 19일
Thanks Robert, had similar problem: +1

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by