I've decided to setup a custom matplotlibrc, and thus I need to pick a backend for matplotlib. What is the best one in terms of not needing to install other additional packages?

I tend to use matplotlib via ipython --pylab, so I want interactive window based plots (when I don't I can switch to Agg).

I've tried WXAgg, but this requires (sensibly enough) WX.


Both Agg and TkAgg do not require any dependencies beyond Python's standard library.

I have had some issues with TkAgg and multi-threading, so if you only need to save to files (and not plt.show()), I would recommend using Agg instead (just replace it where TkAgg appears below).

Either add the following line to your ~/.config/matplotlib/matplotlibrc:

backend: TkAgg

Or the following lines to your python file:

import matplotlib
matplotlib.use('TkAgg') # MUST BE CALLED BEFORE IMPORTING plt
import matplotlib.pyplot as plt

I prefer inline plots with matplotlib to plots in a separate window because it makes it easier to see what I'm doing when I'm fine tuning the Python code.

Python IDE for scientists (spyder) can do inline plotting. To try out this feature open the terminal and type:

sudo apt install python2.7 python-matplotlib spyder ipython  

After the ipython prompt in the IPython console copy/paste the below code and press the Enter key to run it.

import matplotlib.pyplot as plt   
x, y = [-1, 12], [1, 4]  
plt.plot(x, y, marker = 'o')  

enter image description here

Atom text editor with the Hydrogen package for Atom installed can also do inline plotting. I find the Atom interface more complicated to configure than Spyder in which inline plotting with matplotlib works out of the box. I got started with inline plotting in Atom because I wanted to use Atom to make inline plots with other programming languages too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.