3D graph interactive control using checkboxes

10 views (last 30 days)
I have a 3D graph and I would like to allow the user to control the visibility of certain elements (i.e labels,nodes and edges) by adding checkboxes. How do I start ?
Thank you.

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 5 Jan 2018
If you are using a recent MATLAB release, you may be able to get the functionality you are looking for using the ItemHitFcn built-in to the legend.
There is an example in the documentation that shows how to use ItemHitFcn to enable clicking on legend entries to toggle the visibility of items in your plot. Check it out here: Create Interactive Legends Using Callbacks.

More Answers (1)

Camille Fong
Camille Fong on 8 Jan 2018
Edited: Camille Fong on 8 Jan 2018
Thank you Benjamin. I just have another small problem. When I rotate my graph, I am not able to click on the legend anymore. I need to run it again to enable the function. Do you have a solution for this ? Many thanks !
  2 Comments
Benjamin Kraus
Benjamin Kraus on 9 Jan 2018
I'm not sure why rotating your graph would have any effect on the Legend or ItemHitFcn.
Can you give more details, for example:
  1. What is preventing you from clicking on the legend after rotating the graph? What is happening when you try to click on the legend?
  2. What release of MATLAB are you using?
  3. Maybe show some example code?
Camille Fong
Camille Fong on 9 Jan 2018
Edited: Camille Fong on 9 Jan 2018
1. After I rotated the graph I click on the mouse icon and then on the legend and it only allows me to move the legend box. I am not able to click on the elements.
2. I am using R2017b
3. Below is the end of my code with my legend and the function.
L = legend([p1 p2 p3 p4 p5 p7],{'A','B','C','D','E','F'},'location','Best');
L.ItemHitFcn = @hitcallback_ex1;
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
grid on
function hitcallback_ex1(src,evnt)
if strcmp(evnt.Peer.Visible,'on') evnt.Peer.Visible = 'off'; else evnt.Peer.Visible = 'on'; end
end
end
Many thanks again for your help !

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!