Toggle visibility of plots, on the same figure?

157 次查看(过去 30 天)
Attached is the current state of my "project" for which I have SO MANY questions...
First, as I experimented with the script this morning, it dawned on me that my script value would be enhanced by a checkbox that would toggle on and off the visibility of the trisurf plot, so that, I could isolate the data points from the gamut volume to better study their relationship :
Adding a uicontrol checkbox to the script should not be difficult but I sense that I would have to restructure the script very differently? Such that, from the callback function I could issue the call to the trisurf function? Or are there figure or axes options I don't know about that would make this easier?
  1 个评论
Roger Breton
Roger Breton 2022-1-12
A search for "Show or hide figure plot" turned the Plot Browser!!!
Wow! Thank you Mathworks, it's almost what I want, as the figure is "frozen" (can't interact with it while the Plot Browser is active). But it's mighty strong!!

请先登录,再进行评论。

采纳的回答

Roger Breton
Roger Breton 2022-1-12
Almost there! This is what I have, now :
You can see my checkbox, top, left-hand, circled in red -- wow! I added this code to create the control :
cb = uicontrol('Style','checkbox','String','triSurf','Position',[10 500 75 150],'Value',1,'Callback',@checkBoxCallback);
cb.Visible = 'on';
Then I added this function to handle the callback :
function checkBoxCallback(source, event)
global h1;
value = get(source,'Value');
if value == 1
set(h1,'Visible','off');
else
set(h1,'Visible','on');
end
end
Problem is -- please excuse my ignorance -- the checkbox state? When the script is ran, initially, the Value = 1 option in the declaration sets the checkbox state to checked, as far as I can see. This is how the control shows up in the interface. I think it's logical to have the checkbox checked since the trisurf plot is initially visible. When I click on the ckeckbox, however, nothing happens : I have to click one more time and then, the checkbox becomes unchecked but the trisurf is still visible? It's only when I click a third time that the checkbox starts to work as 'expected'. I attached the new code. It's not the end of the world but...
One newbie question in passing, if I may...
I'm using global variables 'sparingly'... Are there better ways to do this, without getting too overly complex?
  3 个评论
Roger Breton
Roger Breton 2022-1-12
Right after initial launch, right after pressing the Run button, I get this :
As you can see, the checkbox is checked. Which is the expected behavior.
Now, this is what happens when I first try to uncheck :
The checkbox is unchecked -- yet, the plot is still visible?
I click the checkbox... and this is what I get :
Now the checkbox is checked YET the plot is not visible?
One more round of clicking and this is what I get :
Do you see what is going on? It is as though the checked state does not match the visibility of the plot.
I changed the initial value in the code back to 0 and changed my code in the function this way :
if value == 0
set(h1,'Visible','off');
else
set(h1,'Visible','on');
end
And now, everything is perfect!!!!
Roger Breton
Roger Breton 2022-1-12
I'll take a look at the the guidata struct. Thanks for the leg up!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by