Visibility through togglebutton on axes syntax

1 view (last 30 days)
I have togglebutton for axes in GUI, visibility on push is working good, but a ineed axes for image graph and when i put comand to axes the togglebutton visibility switch is not working and axes is always visible. Can anybody help with syntax or something for this kind of prob? Code for toggle is under and in axes i have only image(variable from other script).
function showpicture_Callback(hObject, eventdata, handles);
if (get(handles.showpicture,'Value'));
set(handles.axes1,'Visible','on');
else
set(handles.axes1,'Visible','off');
end

Answers (1)

Walter Roberson
Walter Roberson on 21 May 2016
Changing the Visible properties of an axes only changes whether the box and the ticks are visible, not whether the contents of the axes are visible.
The easiest way to set an axes and all of its content to not be visible is to create a uipanel for the area and make the axes a child of the uipanel, and then set the visibility of the uipanel on or off.
  5 Comments
Walter Roberson
Walter Roberson on 24 Jul 2018
If you want to plot into a specific figure or specific axes, you should always pass the handle to the plotting commands.
For example if you used GUIDE to create something that is recorded as axes3 then you could use
ax = handles.axes3;
plot(ax, rand(1,20));
axis(ax, 'image');
Creating a new axes or figure is not required if you already have one.
In the case of your uipanel, you would use the axes that you had already created inside your uipanel as the parent. If you have not already created an axes there, you would do something like
ax = axes('Parent', handles.uipanel7);
and then consistently refer to ax in the plotting commands.
The problem you are encountering in your pushbutton is that you are plotting against the current axes, gca, but your current axes happens to be the background rather than something inside the uipanel. You force it to work by always being specific about where you want to plot instead of relying on the "current" location being the place you want.
VBBV
VBBV on 24 Jul 2018
What I did is ... I used pushbutton to plot the figures by changing axes position, although I have only one axes in main figure window as shown below ax1 = axes('Position',[0.3777 0.05 .495 0.11]); plot(ax1,...) hold on ax2 = axes('Position',[0.3777 0.19 0.495 0.11]); plot(ax2,...) hold on ax3 = axes('Position',[0.3777 0.33 0.495 0.11]); plot(ax3,...)
Now when I try to plot using another Pushbutton, even though I used cla(ax1,'reset')cla(ax2,'reset') cla(ax3,'reset') it does not reset. Instead it plots in the upper most figure with axes ax3. how can I reset the entire axes area when I use another pushbutton ?

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!