Drawing a Graph with Python

Long time ago (somewhere in 2015) I have written an article about Dijkstra and the shortest path. In that article, I draw a graph on a notebook, just to illustrate what I was trying to traverse:

A picture of directed graph, from an article written in 2015.

Today, I was thinking to start set of videos in YouTube, explaining a bit Graph Theory the way I see it. And to do that, I needed some kind of visualization tool, as drawing a graph every time by myself can be pretty tiring. So, I found a way to draw that:

This one is mainly coming out of the box with the magic of nx.DiGraph()

So, after spending a few hours, preparing for a YT video, this is what I came up with:

And returning it is also easy:

Large visualization of tiny graph.

Of course, the video describes the code before putting it into a function and is probably more interesting. The complete code (both the generate_graph_plot() and the one from the video) is in Github here:

Enjoy it! 🙂

Tagged with: , , , ,