Can additional information be added to the directed graph plotting node 'tooltip'?

4 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Christine Tobler
Christine Tobler le 30 Août 2023
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 commentaires
Joe
Joe le 30 Août 2023
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 le 30 Août 2023
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by