Blog

Plotting 3D Graphs with Python, igraph, and Cairo: #cn220 Example

Out of all the visuals I’ve produced, I think the "coolest" is the three-dimensional U.S. Supreme Court citation network 1080p movie I produced with Dan Katz (close friend, coauthor, and newly minted law professor!). 3D networks, especially dynamic ones, really invoke the "wow" factor. Movies are especially important in dynamic cases too, since without the animation, you lose all context and understanding of what led the network to that point. The 3D part may also seem unnecessary at first, but an extra dimension can go a long way to unwinding the hairball that most somewhat-dense networks form. Balancing these benefits with the technical cost and rotation can be hard though, and every network is different.

So how does it work? I thought I’d use the recent #cn220 dataset I posted, along with Python, igraph, and Cairo to demonstrate how 3D network animations can be generated. In this example, we’ll be animating the rotation of a static snapshot of the #cn220 user graph. Here’s an outline of the program:

Calculate a two-dimensional projection of the currently rotated layout.

Draw the vertices and edges in increasing z-order.

Output the surface.

If we wanted to dynamically add and remove vertices or edges from this network, a number of changes need to be made to the algorithm to re-calculate and interpolate layouts across network snapshots. I’ll save these details for another post, but if you’d like to generate dynamic network visualizations like this one, my graphmovie library for Python is designed to do just this.