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?

采纳的回答

Christine Tobler
Christine Tobler 2023-8-30
Yes, you can do this using the dataTipTextRow function:
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
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
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 CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by