3D graph interactive control using checkboxes

9 次查看(过去 30 天)
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.

采纳的回答

Benjamin Kraus
Benjamin Kraus 2018-1-5
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.

更多回答(1 个)

Camille Fong
Camille Fong 2018-1-8
编辑:Camille Fong 2018-1-8
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 个评论
Benjamin Kraus
Benjamin Kraus 2018-1-9
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 2018-1-9
编辑:Camille Fong 2018-1-9
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 !

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by