Mind Map with Python

I always wanted a program to generate mind maps. This is the first attempt to do it with Python.

This is an example of the output we will get.

Install Graphviz (eventually with chocolatey)

To make a mind map with Python you need to install Graphviz at this web page.

You could use also chocolatey to install Graphviz.

Chocoloatey installs Graphviz. Go to chocolatey and install it.

Watch the video to see how I did it.

Install pydot

Now we’re ready to install pydot in the cmd (command line) or powershell:

pip install pydot

Ready for the code

You should also go in the environmental variable settings (watch the video) and insert the path to Graphviz in it.

The path is also to paste into the code. In fact after you imported pydot (and os), you need to add this line of code:

Rememeber that the environ path is the one on my computer. You gotta put the one on your that could be the same of mine, but it is not sure, you could have installed somewhere else.

Now we are ready.

Risultati immagini per gif ready

Create a Dot istance (let’s call it graph)

The graph type could have been also graph. The UD means Up down, for the vertical oriented maps. If you want a left to right map, use LR instead.

Now we create the root node, the master, the topic of whatever you want to call the keyword that is the start of the map. Let’s say the topic is Pydot!

Now let’s create adn Edge object with the name of the root and his child as arguments. We will add the edge to graph with the add_edge method. Then we save the image of the map and show it.

We could stop here and save an image of the map:

Create 2 children of a child

Now, to add two children to How to install it you can add

The whole code being:

The output would be:

As you can see, it is easy, but a bit tedious. If you watch the video you will see me trying to abstract a little bit the code, so that it is less annoying to add the childrens… there will be for sure better ways, but I leave them to your imagination or to future articles…

A nice example (the one you see in the video)

And now…

The live coding video of Pydot to make Mind Maps and Concepts Maps with Python

Post written by Avatar A python enthusiast

Higlighted videos

Speech recognition game
Pygame cheatsheets
Let's start using pygame to make games! Pretty fun assured.