I have a python dataframe that I would like to visualize in graphviz. Everything works fine except that I would like to change the color of the nodes after plotting the network.
The dataframe looks something like this:
Sender Receiver Amount Sender_Part_Of_Group? Receiver_Part_Of_Group?
A B 88 1 0
C B 71 0 0
B D 32 0 1
D A 26 1 1
I used G = nx.convert_matrix.from_pandas_edgelist(df,"Sender","Receiver","Amount", create_using = nx.multiDiGraph())
to create a NetworkX object.
I then used dot = nx.nx_pydot.to_pydot(G)
to create a dot object.
Finally, I did this:
from graphviz import Source
sc = Source(dot, filename = "plot", format = "png", engine = "fdp")
sc.render
This is the graph that I got.
Now I want to color all of the nodes based on whether they are part of the group (last two columns of the df) or not. What is the best way to go forward with this? I don't want to construct the nodes and edges manually because the DataFrame is quite large. This is what I would ideally prefer to have since A and D are part of the group and B and C are not: