List of All Available Matplotlib Backends

List of all available matplotlib backends

You can access the lists

matplotlib.rcsetup.interactive_bk
matplotlib.rcsetup.non_interactive_bk
matplotlib.rcsetup.all_backends

the third being the concatenation of the former two. If I read the source code correctly, those lists are hard-coded though, and don't tell you what backends are actually usable. There is also

matplotlib.rcsetup.validate_backend(name)

but this also only checks against the hard-coded list.

In Matplotlib, is there a way to know the list of available output format

If you create a figure, you can get the available supported file format with the canvas object :

import matplotlib.pyplot as plt
fig = plt.figure()

print fig.canvas.get_supported_filetypes()

>>> {
'svgz': 'Scalable Vector Graphics',
'ps': 'Postscript',
'emf': 'Enhanced Metafile',
'rgba': 'Raw RGBA bitmap',
'raw': 'Raw RGBA bitmap',
'pdf': 'Portable Document Format',
'svg': 'Scalable Vector Graphics',
'eps': 'Encapsulated Postscript',
'png': 'Portable Network Graphics'
}

and it will list all the formats in which you can output your current object.

What is the default GUI backend for Matplotlib?

The backend selection logic is not very transparent and not well documented.

In modern matplotlib there is no "default backend", i.e. the rcParams['backend'] is set to a "sentinel".

Upon importing matplotlib the first working backend from a candidate list ["macosx", "qt5agg", "qt4agg", "gtk3agg", "tkagg", "wxagg"] is chosen.

In order to avoid this automatic selection, you can set the backend manually via the rcParams['backend'] parameter or the MPLBACKEND environment variable. That part is documented

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. when plotting figure with pyplot on Pycharm

Solution 1: is to install the GUI backend tk

I found a solution to my problem (thanks to the help of ImportanceOfBeingErnest).

All I had to do was to install tkinter through the Linux bash terminal using the following command:

sudo apt-get install python3-tk

instead of installing it with pip or directly in the virtual environment in Pycharm.

Solution 2: install any of the matplotlib supported GUI backends

  • solution 1 works fine because you get a GUI backend... in this case the TkAgg
  • however you can also fix the issue by installing any of the matplolib GUI backends like Qt5Agg, GTKAgg, Qt4Agg, etc
    • for example pip install pyqt5 will fix the issue also

NOTE:

  • usually this error appears when you pip install matplotlib and you are trying to display a plot in a GUI window and you do not have a python module for GUI display.
  • The authors of matplotlib made the pypi software deps not depend on any GUI backend because some people need matplotlib without any GUI backend.

How can I set the 'backend' in matplotlib in Python?

Your currently selected backend, 'agg' does not support show().

AGG backend is for writing to file, not for rendering in a window. See the backend FAQ at the matplotlib web site.

ImportError: No module named _backend_gdk

For the second error, maybe your matplotlib distribution is not compiled with GTK support, or you miss the PyGTK package. Try to install it.

Do you call the show() method inside a terminal or application that has access to a graphical environment?

Try other GUI backends, in this order:

  • TkAgg
  • wxAgg
  • Qt5Agg
  • Qt4Agg

Matplotlib: display plot on a remote machine

If you use matplotlib on Mac OS X on the remote machine (B), you must first make sure that you use one of the X11-based display back-ends, since the native Mac OS X back-end cannot export its plots to another display. Selecting a back-end can be achieved with

import matplotlib
matplotlib.use('GTK') # Or any other X11 back-end

The list of supported back-ends can be obtained by giving use() an incorrect back-end name: matplotlib then prints an error message listing the possible back-ends.

ssh X11 forwarding can then be used to display matplotlib plots.



Related Topics



Leave a reply



Submit