import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
#adjacency matrix
df = pd.DataFrame(
[[0, 1, 1, 1, 0, 0, 1, 0],
[1, 0, 1, 1, 1, 0, 0, 0],
[1, 1, 0, 0, 1, 1, 1, 0],
[1, 1, 0, 0, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 1, 1],
[0, 0, 1, 0, 1, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 0, 1],
[0, 0, 0, 0, 1, 1, 1, 0]]
)
G = nx.from_pandas_adjacency(df)
colors = nx.coloring.greedy_color(G, strategy='largest_first')
colors = [colors[k] for k in sorted(colors.keys())]
#use help(nx.draw_networkx()) to find the params of nx.draw
nx.draw(G, with_labels=True, node_color=colors)
plt.show()