Throughout this chapter, we have been visualizing social networks to help develop our understanding and intuition around graphs. In this recipe, we dig a little bit deeper into graph visualization.
Complete this list of steps to gain a better understanding of graph visualization in Python:
- NetworkX wraps matplotlib or graphviz to draw simple graphs using the same charting library that we saw in the previous chapter. This is effective for smaller-size graphs, but with larger graphs, memory can quickly be consumed. To draw a small graph, simply use the
networkx.draw
function, and then usepyplot.show
to display it:
>>> import networkx as nx >>> import matplotlib.pyplot as plt >>> nx.draw(graph) >>> plt.show()
- There is, however, a rich drawing library underneath that lets you customize how the graph looks and is laid out with many different layout algorithms...