What is the easiest way to print a graph in Python? i.e. I am wanting to visualize the maximum clique of a graph.
My current data structures are:
adjacency_matrix = [[False, True, False, ...],
[True, False, True, ...],
..]
adjacency_set = [[45, 2], [1, 32], ...]
max_clique = [23, 143, 1, 2, 42, 12, 3, ...] # the vertices in the max clique
Would I use matplotlib to do this?
Consider using networkx package for creating and manipulating graphs. It also has visualization functions such as drawing with matplotlib.
Note that you will need to convert your data structure to one that can initialize networkx graph. here is the docs.
Also you might want to read this answer on how to visualize maximal cliques.
example:
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
A = np.matrix([[1,1],[2,1]])
G = nx.from_numpy_matrix(A)
nx.draw(G)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With