NetworkX: drawing large graphs?
I have a graphML
file that represents relation between multiple SQL tables (nodes and edges).
I am using networkx to parse the file and matplotlib
to draw it. The issue I have is that my graph is quite big (around 150 nodes) and hard to read. I do not have any experience in computer graph / drawing and the final result looks messy, is there a way to improve the readability of the graph (another library for instance, larger image,...) without decreasing the total number of nodes?
import networkx as nx
import matplotlib.pyplot as plt
input_graph = nx.read_graphml("graph.graphml")
to_remove = []
for node, data in input_graph.nodes(data=True):
if data['zone'] != 'gold' or input_graph.degree(node) == 0:
to_remove.append(node)
input_graph.remove_nodes_from(to_remove)
nx.draw(input_graph, with_labels=True)
plt.show()
Some of the options are:
-
shorten node labels and make use of the colours to differentiate groups/categories of nodes (e.g. nodes that belong to group A are coloured with red, nodes that belong to B are blue, etc.);
-
experiment with the layout: the default layout is spring layout, but another layout might give you less clutter, e.g. circular layout;
-
use datashader's edge bundling.