How to distinguish specific nodes in an undirected graph ?

1 visualización (últimos 30 días)
Hello,
I have an attribute of an undirected graph called G.Nodes.Load. Where in every time step some of its values change to -inf. And I'm trying to visualize this process using Graph and Network Algorithms.
I tried the following:
figure; h = plot(G);
highlight(h, G.Nodes.Load == -inf, 'NodeColor','r' )
Kindly check the attached graph plots. Is there a clearer way than this?
EDIT : I assigned random values for "G.Nodes.Load", and then I created another attribute "G.Nodes.Capacity" :
Load = (1000-800)*rand(5000,1)+800;
Capacity = (1+0.2) * Load;
G.Nodes.Load = Load;
G.Nodes.Capacity = Capacity;
Now I'm trying to assigne a red color for any value of Load that exceeds its corresponding capacity, a lighter red color for 80% usage of capacity (Load./capacity), light blue for 50% usage, and dark blue for 25% usage. I think in this case I don't have to highlight the nodes but instead I need to choose another way in visualizing the load./capacity ratio, am I correct?
Thanks!

Respuesta aceptada

Steven Lord
Steven Lord el 22 de Feb. de 2022
Create a sample graph and define some sample load and capacity data.
rng default
G = graph(bucky);
Load = (1000-800)*rand(numnodes(G),1)+800;
Capacity = (1+0.2*rand(numnodes(G), 1)) .* Load;
Set the node data to the Nodes table in G.
G.Nodes.ID = (1:numnodes(G)).';
G.Nodes.Load = Load;
G.Nodes.Capacity = Capacity;
G.Nodes.Usage = G.Nodes.Load ./ G.Nodes.Capacity;
Plot the graph.
h = plot(G);
Select some nodes.
nodesGreaterThan97Percent = G.Nodes.Usage > 0.97;
Get info about these nodes.
info = G.Nodes(nodesGreaterThan97Percent, :)
info = 9×4 table
ID Load Capacity Usage __ ______ ________ _______ 8 909.38 934.59 0.97302 9 991.5 1021.1 0.97101 31 941.21 955.49 0.98506 32 806.37 815.07 0.98933 36 964.69 989.76 0.97468 39 990.04 992.4 0.99763 52 935.94 951.63 0.98351 55 823.8 848.91 0.97043 59 917.05 931.39 0.98461
Highlight the selected nodes in the plot.
highlight(h, nodesGreaterThan97Percent, 'NodeColor', 'r')

Más respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 21 de Feb. de 2022
Here one potential err in your code is logical (==). One can determine when the value of a variable goes to infinity with this fcn: isinf().
Moreover, MATLAB plot fcn skips infinity values and thus, you'd need to determine when the values go to infinity and assign them some specific value in order to plot them. And then you can do some highlights.
  2 comentarios
Waseem AL Aqqad
Waseem AL Aqqad el 21 de Feb. de 2022
You misunderstood my question.
I'm plotting a Graph object (Complex Network) not data points. So, I'm visulizing the nodes with this attribute G.Nodes.Load = -inf. What I did is quite correct but I'm wondering if there is a better way.

Iniciar sesión para comentar.

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by