Controlling current axes within programmatic UI (GUI layout toolbox)
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
D. Plotnick
el 30 de Mzo. de 2016
Comentada: John BG
el 19 de Oct. de 2017
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!
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!