How to control the appearance of child objects in an axis while working with GUI?

13 次查看(过去 30 天)
Hi
I am creating a GUI which has different number of axis handles. I am controlling its appearance through pushbutton callback. When i try to change the axis visibility to 'off', its parent axis becomes invisible whereas the the child axis objects are still in visible state. Can someone suggest how to control the visibility of child objects.
FYI:
In below reference, the left side (handles.axes1) of the axis will be displayed when i call the pushbutton 1. And when i try to call the pushbutton 2 the handles.axes1 will be 'off' (visibility) and the remaining handles.axes will be 'on'(visibility). But in contrary, the handles.axes1 also displayed even i use the following command:
set(handles.axes1,'Visible','off'); % pusbutton 2 callback

采纳的回答

Image Analyst
Image Analyst 2021-8-31
Try this demo and I think you will understand how to do it:
% Demo to show how to show or hide an entire axes control.
% By Image Analyst
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
fontSize = 13;
format short g
fprintf('Beginning to run %s.m ...\n', mfilename);
% Create sample data
x = 1 : 10;
y1 = rand(1, 10);
plot(x, y1, 'r.-', 'LineWidth', 2, 'markerSize', 15);
hold on;
y2 = rand(1, 10);
plot(x, y2, 'b.-', 'LineWidth', 2, 'markerSize', 15);
grid on;
title('Title');
xlabel('x');
ylabel('y');
legend('y1', 'y2');
% Hide everything on the axes:
promptMessage = sprintf('Click OK to hide the axes.');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if contains(buttonText, 'Cancel', 'IgnoreCase', true)
return; % or break or continue.
end
ShowOrHideAxes(gca, false)
% Show/restore everything on the axes:
promptMessage = sprintf('Click OK to show the axes.');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if contains(buttonText, 'Cancel', 'IgnoreCase', true)
return; % or break or continue.
end
ShowOrHideAxes(gca, 'on')
%=====================================================================
% Sets visibility of all objects in the specified axes.
% Sample calls:
% ShowOrHideAxes(gca, 'off');
% ShowOrHideAxes(gca, false);
% ShowOrHideAxes(gca, 'on');
% ShowOrHideAxes(gca, true);
function ShowOrHideAxes(h, visible)
if ischar(visible)
if strcmpi(visible, 'off')
visible = false;
else
visible = true;
end
end
if visible
vis1 = 'on';
vis2 = true;
vis3 = 'show';
else
vis1 = 'off';
vis2 = false;
vis3 = 'hide';
end
axis(vis1); % Turn off axes and grid lines.
h.Toolbar.Visible = vis1; % Turn off/on popup toolbar in upper right of axes.
legend(vis3); % Turn off/on legend.
axesHandlesToChildObjects = findall(h);
% If you want to show or hide only plot lines (data) you can do
% axesHandlesToChildObjects = findobj(h, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
numObjects = length(axesHandlesToChildObjects);
for k = 1 : numObjects
axesHandlesToChildObjects(k).Visible = vis2;
end
end
return; % from ShowOrHideAxes
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by