I want to visualize a social network with nodes and edges, with colors of nodes representing values of attributes. It will be nice if I can do it with tools in python (like networkx), but I am also open to other tools (like Gephi , graph-tools) . The nodes and edges that I have in my social network are in the form of numpy arrays. I want nodes of this visualization to be colored according to values of attributes.
Each row in the nodes array points to an user. Each column in the nodes array points to an attribute. The values in each column of the nodes array point to attribute values. Here is an example of a nodes array with 10 users and 3 attributes (with names [Att1
, Att2
, Att3
].
Nodes = np.array([[1,2,4],[1,3,1],[2,2,1],[1,1,2],
[1,2,2],[2,1,4],[1,2,1],[2,0,1],
[2,2,4],[1,0,4]])
Similarly, the edges array (adjacency matrix) is a square array of size number of nodes *
number of nodes. A value of 1 in the adjacency matrix points to a presence of an edge between two nodes, and a value of 0 points to absence of an edge. Here is an example of an edges array.
Edges = np.random.randint(2, size=(10,10))
Let's say I want the nodes to be colored according to attribute values given in the middle column of Nodes
(i.e. Attribute_Value = Nodes[:,1] = [2, 3, 2, 1, 2, 1, 2, 0, 2, 0])
There are four unique attribute values [0,1,2,3]
so, I will like to have four different colors for the nodes. In my actual graph, I have many more unique values for attributes. Also, I have tens of thousands of nodes, so I will like to be able to adjust the sizes (radii) of nodes in my plot.
Following a previous post of mine, I have tried this:
import networkx as nx
G = nx.from_numpy_array(Edges)
nx.draw(G, with_labels=True)
But, results from the above code snippet do not let me choose colors as per attribute values. Also, I will need to adjust sizes of nodes. How can I visualize social graphs in the described way?