3D graph interactive control using checkboxes

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일

1 개 추천

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.

댓글 수: 2

I didn't know about that!
Thank you ! This is quick and easy !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Camille Fong
Camille Fong 2018년 1월 8일
편집: Camille Fong 2018년 1월 8일

0 개 추천

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

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 !

댓글을 달려면 로그인하십시오.

카테고리

질문:

2018년 1월 4일

편집:

2018년 1월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by