Skip to content

Guide · Open source

How to use PlotNeuralNet: install LaTeX and draw neural network diagrams

Updated · written with AI from the project's own documentation and checked against our catalogue data

PlotNeuralNet is an open-source collection of LaTeX code for drawing neural network architecture diagrams, such as convolutional networks, by describing the layers in text instead of drawing them by hand. It is aimed at figures for reports, papers and presentations. This guide shows you how to set up the LaTeX packages, run the bundled example, and generate a diagram from a Python list of layers.

PlotNeuralNetHarisIqbal88/PlotNeuralNet · ★ 25.1k · MIT

Quick start

  1. 1Install LaTeX. Install texlive on Ubuntu or MiKTeX on Windows, using the package list in the README for your version.
  2. 2Install a bash runner on Windows. Install Git bash or Cygwin so the build script can run.
  3. 3Clone the repository. Run git clone on the PlotNeuralNet repository to get the code and examples.
  4. 4Run the test example. Go into pyexamples/ and run bash ../tikzmake.sh test_simple to confirm the build works.
  5. 5Define your layers. Write a Python list of layers using to_Conv, to_Pool, to_SoftMax and to_connection.
  6. 6Generate and build. Call to_generate to write a .tex file, then run bash ../tikzmake.sh with your script name.

What you need before you start

PlotNeuralNet is a clone-and-build project. You need a LaTeX distribution: texlive on Ubuntu, or MiKTeX on Windows. On Windows you also need a bash runner, and the README recommends Git bash or Cygwin. Python is needed only if you want to use the Python interface.

  • LaTeX distribution: texlive (Ubuntu) or MiKTeX (Windows)
  • Windows only: Git bash or Cygwin
  • Python, for the Python interface

Install the LaTeX packages on Ubuntu

The README lists different packages depending on the Ubuntu version. For Ubuntu 18.04.2 it points to a guide and lists four packages. For Ubuntu 16.04 it lists only texlive-latex-extra. The README notes the package list is based on an external guide, so check it against your system if something is missing.

  • Ubuntu 16.04: texlive-latex-extra
  • Ubuntu 18.04.2: texlive-latex-base, texlive-fonts-recommended, texlive-fonts-extra, texlive-latex-extra
sudo apt-get install texlive-latex-base sudo apt-get install texlive-fonts-recommended sudo apt-get install texlive-fonts-extra sudo apt-get install texlive-latex-extra

Install on Windows

On Windows, download and install MiKTeX from its download page. Then install a bash runner such as Git bash or Cygwin, since the example is run with a bash script.

  • Install MiKTeX from miktex.org/download
  • Install Git bash or Cygwin to run the bash script

Get the code and run the example

Clone the repository, move into the pyexamples folder, and run the test_simple example through the tikzmake.sh script. The script is in the top-level folder of the repository, so the path starts with ../.

If the example builds, you have confirmed that LaTeX and the packages work on your machine.

git clone https://github.com/HarisIqbal88/PlotNeuralNet cd pyexamples/ bash ../tikzmake.sh test_simple

Write your own diagram with the Python interface

Create a new directory and a Python file. Import the tikzeng module from pycore, then define your architecture as a Python list. Each entry is a function call that adds a layer, such as to_Conv, to_Pool or to_SoftMax, with positions set by offset and to arguments. Use to_connection to link two layers by name, and wrap the list with to_head, to_cor, to_begin and to_end.

Then call to_generate to write a .tex file, and build it with tikzmake.sh using the file name without the extension.

  • to_head, to_cor, to_begin, to_end: set up and wrap the document
  • to_Conv, to_Pool, to_SoftMax: add layer shapes
  • to_connection: draw an arrow between two named layers
  • to_generate: write the LaTeX file
import sys sys.path.append('../') from pycore.tikzeng import * # defined your arch arch = [ to_head( '..' ), to_cor(), to_begin(), to_Conv("conv1", 512, 64, offset="(0,0,0)", to="(0,0,0)", height=64, depth=64, width=2 ), to_Pool("pool1", offset="(0,0,0)", to="(conv1-east)"), to_Conv("conv2", 128, 64, offset="(1,0,0)", to="(pool1-east)", height=32, depth=32, width=2 ), to_connection( "pool1", "conv2"), to_Pool("pool2", offset="(0,0,0)", to="(conv2-east)", height=28, depth=28, width=1), to_SoftMax("soft1", 10 ,"(3,0,0)", "(pool1-east)", caption="SOFT" ), to_connection("pool2", "soft1"), to_end() ] def main(): namefile = str(sys.argv[0]).split('.')[0] to_generate(arch, namefile + '.tex' ) if __name__ == '__main__': main()

Build the diagram and edit it

Run your script's name through tikzmake.sh from the folder where the file lives. Because the diagram is code, you can change the numbers, positions and captions, rebuild, and track changes in version control. The examples folder has more LaTeX usage examples.

bash ../tikzmake.sh my_arch

What people use it for

  • Drawing a convolutional network figure for a research paper
  • Adding a neural network diagram to a student report
  • Keeping architecture diagrams in a Git repository so they can be edited and reviewed
  • Producing a figure for a presentation from the same code as your model description

Frequently asked questions

Is PlotNeuralNet free to use?

PlotNeuralNet is released under the MIT licence, as listed on its repository. The MIT licence allows use, modification and redistribution, subject to its terms.

What do I need to install to use PlotNeuralNet?

You need a LaTeX distribution: texlive on Ubuntu or MiKTeX on Windows. On Windows you also need Git bash or Cygwin to run the bash script, and Python if you want the Python interface.

Why does PlotNeuralNet need so many texlive packages?

The README lists several texlive packages for Ubuntu, including texlive-latex-base, texlive-fonts-recommended, texlive-fonts-extra and texlive-latex-extra, because the diagrams are built with LaTeX. The README does not explain each package's role, so install the listed ones if a build fails.

Can PlotNeuralNet draw recurrent neural networks?

The README's TODO lists adding examples for RNNs and similar networks as planned work, so it is not listed as supported yet. The layer shapes it mentions are the ones available now.

How is PlotNeuralNet different from NN-SVG or draw.io?

PlotNeuralNet builds diagrams from LaTeX code, so the figure is text you can edit and version-control. NN-SVG and draw.io are visual tools, and draw.io is drag-and-drop. Choose PlotNeuralNet if you are comfortable with LaTeX; choose a visual tool if you want to draw without code.

Can I use PlotNeuralNet without writing LaTeX?

You still need LaTeX installed to build the output, but the Python interface lets you describe layers in a Python list and generates the .tex file for you. You do not have to write the LaTeX by hand for the layer shapes it provides.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

PlotNeuralNet suits researchers, students and anyone already comfortable with LaTeX or Overleaf who wants clean, editable architecture figures generated from code. If you need a quick drag-and-drop diagram, do not have a LaTeX setup you can install, or need shapes or RNN diagrams the README does not yet cover, pick a visual tool such as NN-SVG or draw.io.

Install options & downloads