Search code examples
matlabuser-interfaceplotaxes

plots in overlapping multiple axes MATLAB GUI


I have 2 axes in my GUI which overlap (they have same positions). 2 separate radio buttons trigger each. When one is triggered, the other should be suppressed. I'll show different plots in each. However, when I use 'Visible', only axes are gone not the plots. How can I solve this?

value(1) = get(S.rbh_1,'value'); value(2) = get(S.rbh_2,'value');

if value(1) == 1
    set(S.rbh_2,'value',0);
    set(S.axes1,'Visible','on');
    set(S.axes2,'Visible','off');
elseif value(2) == 1
    set(S.rbh_1,'value',0);
    set(S.axes1,'Visible','off');
    %cla(S.axes1);
    set(S.axes2,'Visible','on');
end

If I use cla(), I cannot draw previously existing plots.


Solution

  • Here is aminimal exemple reproducing your problem:

    ezplot('x^2');
    set(gca, 'Visible', 'off');
    

    Actually, this is a normal behavior. According to the documentation:

    The Visible property of an axes object does not affect the children of axes.

    To make both the axes and all its children elements invisible, you can use findall in combination with arrayfun. Just replace:

    set(gca,'Visible','off');
    

    with

    arrayfun(@(x) set(x, 'Visible', 'off'), findall(gca));
    

    In your exemple, you have to replace gca by S.axes1 or S.axes2.

    Best,