3D graph interactive control using checkboxes

10 ビュー (過去 30 日間)
Camille Fong
Camille Fong 2018 年 1 月 4 日
編集済み: Camille Fong 2018 年 1 月 9 日
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.
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 4 日
Read about uicontrol() style 'check'

サインインしてコメントする。

採用された回答

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.
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 5 日
I didn't know about that!
Camille Fong
Camille Fong 2018 年 1 月 5 日
Thank you ! This is quick and easy !

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by