I have a set of nodes with an adjacency matrix. I want to color these nodes based on the array P
such that node 1 = P[0]
, node 2 = P[1]
, node 3 = P[2]
and so on with a colorbar showing the range of values. The current and expected outputs are presented.
import numpy as np
import networkx as nx
G = nx.grid_2d_graph(3,3)
new_nodes = {e: n for n, e in enumerate(G.nodes, start=1)}
new_edges = [(new_nodes[e1], new_nodes[e2]) for e1, e2 in G.edges]
G = nx.Graph()
G.add_edges_from(new_edges)
nx.draw(G, with_labels=True)
A1 = nx.adjacency_matrix(G)
A=A1.toarray()
print([A])
P=np.array([10.5,20.7,30.7,40.1,50.6,60.3,70.6,80.9,90.8])
The current output is
The expected output is