Controlling current axes within programmatic UI (GUI layout toolbox)

1 回表示 (過去 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 Center および File ExchangeGraphics Object Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by