Can additional information be added to the directed graph plotting node 'tooltip'?
4 次查看(过去 30 天)
显示 更早的评论
Hello.
I'm working with visualizing directed graphs in MATLAB and am trying to determine if there is a way to add additional graph metadata to the 'tooltip' that appears when hovering over a node. The code and screenshot below may help explain my question a bit more.
nodeNames = {'Node A', 'Node B', 'Node C', 'Node D', 'Node E', 'Node F'};
edges = [[1 3]; [2 3]; [3 4]; [4 6]; [5 6]];
G = digraph(edges(:,1), edges(:,2), [], nodeNames);
plot(G)
What I want to do is add additional information where it says "In Degree 2" & "Out Degree 1".
For example, could I add another line that says " Metadata Value 4.53" and do this in a way that the value is variable with each node?
If there's not a way to do this on the tooltip, is it possible to do it some other way besides ad-hoc changing the node names to include the information?
0 个评论
采纳的回答
Christine Tobler
2023-8-30
nodeNames = {'Node A', 'Node B', 'Node C', 'Node D', 'Node E', 'Node F'};
edges = [[1 3]; [2 3]; [3 4]; [4 6]; [5 6]];
G = digraph(edges(:,1), edges(:,2), [], nodeNames);
p = plot(G);
newrow = dataTipTextRow('Metadata Value', rand(numnodes(G), 1)); % Provide one value per node
p.DataTipTemplate.DataTipRows(end+1) = newrow;
datatip(p);
3 个评论
Joe
2023-8-30
Sorry if this is better done as a new thread, but it is relevant to the tool tip. And yes, this is excellent! In this simple graph, in/out degree are pretty obvious. Can the tool tip be configured to remove that information?
Christine Tobler
2023-8-30
Yes, you can use
p.DataTipTemplate.DataTipRows([2 3]) = [];
to delete those rows. You could also modify those rows by changing their Label and Value properties.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!