HOW-TO: Embed a DOT graph with GraphViz

Graphes?

I am showing here an "experimental" Sphinx feature, to easily embed graphs written in plain text with a rST tag .. graphviz::, and converted to nice images with the world-famous software GraphViz.

This feature is provided by the sphinx.ext.graphviz extension, included by default in sphinx since its version 0.6.

This directive graphviz uses the DOT Graph language to describe a graph (directed or not). This language is a world-standard in Computer Science, everyone uses it: engineers, researchers, professors etc.

Avis

If the following graphs are not well displayed, that is probably because your browser does not support the SVG format. Try to use Mozilla Firefox instead.

Examples

.. graphviz:::

Sphinx is a software than basically implements these conversion steps:

.. digraph:::

We can also write directed graphs.

For instance Sphinx autodoc (and a script like pytorst.py) implements this conversion step:

.. graph:::

This directive is for non-directed graphs.

LaTeX

pdflatex implements this conversion (for example with my resume, written in LaTeX):

HeVeA does another transformation:

The "Hautes-Alpes" region in France

I was born and I grew up in :red:`Briançon`, in the Hautes-Alpes, until I was 16, before leaving to study at the Lycée Thiers in Marseille.

In the Hautes-Alpes, the main cities are the following (an edge means that the two towns are in the same valley ie. connected with a river!):

An external file

This rST command can also automatically fetch an external file. For instance here is a dependance graph (for an old network game project I wrote in 2012) generated via pyreverse, and included here with .. graphviz:: .graph.dot (the file is called .graph.dot).

Avis

This graph is not correctly scaled...


Using this for the scipy doc

For scipy scipy.sparse.csgraph module, its documentation shows two small graphs, initially written in ASCII, but I wanted to try to add nice SVG files instead.

I opened the issue (#5344), this comment is related also. This pull request (#5345) was not interesting: the raw SVG included in the rST page is not working for PDF output neither docstring inspection (with IPython or other).

Graph G1:

Graph G1 0 0 1 1 0--1 2 2 2 0--2 1

Graph G2:

Graph G2 0 0 1 1 0--1 2 2 2 0--2 0

Another extension: sphinx.ext.todolist

This page also tests the feature provided by the sphinx.ext.todolist extension. This extension adds a directive .. todo:: which allows to add a TODO, i.e. one thing to do, to fix or to work on.

And then, you can display a TODO list with the directive .. totolist::, like I do in the todo.html page.