Skip to content
Live plots with matplotlib with a simple interface
Branch: master
Clone or download
Latest commit fee32bf Oct 31, 2018


Live Plotter

This package provides a simple interface to do live plotting and realtime plotting using matplotlib.

Detailed documentation here:

Supports Python 2.7+ and Python 3.2+


System dependencies:

  • zeromq

Python dependencies are listed in requirements.txt


# Use pip3 and python3 to use Python 3.x
pip install --process-dependency-links

You can also install by cloning the repository:

git clone
cd live-plotter
# Use pip3 and python3 to use Python 3.x
pip install -r requirements.txt
python install

Notes about backends

This package has been tested with the TkAgg backend on linux and Gtk3Agg backend on macOS, but none of the other combinations.

To set the default backend on linux, edit $HOME/.config/matplotlib/matplotlibrc and add the following line:

backend : tkagg

This backend requires tkinter to be installed -- the python-tk ( python3-tk) package on Ubuntu/Debian

To set the default backend on macOS, edit $HOME/.matplotlib/matplotlibrc and add the following line:

backend : gtk3agg

This backend requires the pygobject package to be installed -- the py27-gobject3 ( py36-gobject3 -- replace py36 with your python3 version) package on MacPorts.

See [1] and [2] for more information



Record data to be plotted

It consists of two parts: a PlotRecorder and a Plotter.

For any code you have, you can record the values that you want to plot using the PlotRecorder as follows:

from liveplotter.plotrecorder import PlotRecorder
plot_recorder = PlotRecorder()

def simulate():
  # Your simulation code here
  x = ...
  x_sq = x**2
  plot_recorder.record("x_sq", x_sq)

This sends the recorded variable to a ZeroMQ Queue, but otherwise is very low overhead and doesn't affect your simulation, even if you decide not to do live plotting for any particular run.

After the simulation is finished, call plot_recorder.close('x_sq') to do a clean shutdown.

Set up live plotting

To actually do live plotting, you can do one of two things:

Use one of the existing live plot classes

There are plotting methods available for single lines, multiple lines, images and spikes. Look at the documentation in the classes in in the documentation

Write your own live plot class

would implement a Plotter in a different file that inherits from PlotterBase as follows:

from liveplotter.plotrecorder import PlotterBase

class YourPlotter(PlotterBase):
    def init(self):
        # Make sure you call the super `init` method. This initializes `self.plt`
        super().init()"First initializing plots in thread %s", self.entity_name)
        # It is necessary to assign the variable `self.fig` in this init function

        self.fig, = self.plt.subplots()

        # Your initialization code here

        return self

    def plot_loop(self, var_value, i):
        # Implements the plotting loop.
        logger.debug("Plotting %s in %s", self.var_name, self.entity_name)

        # Plot the variable and return a matplotlib.artist.Artist object

And start it with:



You can find an example in the example directory.

To run it, do cd example; ./

It runs the two files example/ and example/ and shows the fractal generation live.

The animation will look like this:


Building documentation locally

After cloning the repository, go to the doc directory and first install the documentation requirements with

cd doc
pip install -r requirements.txt  # use pip3 for python3

Then run:

make html

and open the documentation at doc/build/html/index.html

You can’t perform that action at this time.