Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Christine Tobler
Christine Tobler il 30 Ago 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 Commenti
Joe
Joe il 30 Ago 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 il 30 Ago 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by