Controlling current axes within programmatic UI (GUI layout toolbox)

4 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by