List of all available matplotlib blade servers

The current backend name is available through

 >>> import matplotlib.pyplot as plt
 >>> plt.get_backend ()
 'GTKAgg'

Is there a way to get a list of all the backends that can be used on a particular machine?

+64
python matplotlib
Feb 23 2018-11-11T00:
source share
6 answers

You can access the lists

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

the third is the concatenation of the first two. If I read the source code correctly, these lists are hard-coded and do not tell you which backends are really usable. There is also

 matplotlib.rcsetup.validate_backend(name) 

but it also only checks the hard list.

+47
Feb 23 2018-11-21T00:
source share

Here is a modification of the script posted earlier. It finds all supported backends, checks them and measures their fps. In OSX, python crashes when it comes to tkAgg, so use at your own risk;)

 from __future__ import print_function, division, absolute_import from pylab import * import time import matplotlib.backends import matplotlib.pyplot as p import os.path def is_backend_module(fname): """Identifies if a filename is a matplotlib backend module""" return fname.startswith('backend_') and fname.endswith('.py') def backend_fname_formatter(fname): """Removes the extension of the given filename, then takes away the leading 'backend_'.""" return os.path.splitext(fname)[0][8:] # get the directory where the backends live backends_dir = os.path.dirname(matplotlib.backends.__file__) # filter all files in that directory to identify all files which provide a backend backend_fnames = filter(is_backend_module, os.listdir(backends_dir)) backends = [backend_fname_formatter(fname) for fname in backend_fnames] print("supported backends: \t" + str(backends)) # validate backends backends_valid = [] for b in backends: try: p.switch_backend(b) backends_valid += [b] except: continue print("valid backends: \t" + str(backends_valid)) # try backends performance for b in backends_valid: ion() try: p.switch_backend(b) clf() tstart = time.time() # for profiling x = arange(0,2*pi,0.01) # x-array line, = plot(x,sin(x)) for i in arange(1,200): line.set_ydata(sin(x+i/10.0)) # update the data draw() # redraw the canvas print(b + ' FPS: \t' , 200/(time.time()-tstart)) ioff() except: print(b + " error :(") 
+46
Dec 05
source share

There is a hardcode list mentioned by Sven, but to find all the backends that Matplotlib can use (based on the current implementation to configure the backend), you can check the matplotlib / backends folder.

The following code does the following:

 import matplotlib.backends import os.path def is_backend_module(fname): """Identifies if a filename is a matplotlib backend module""" return fname.startswith('backend_') and fname.endswith('.py') def backend_fname_formatter(fname): """Removes the extension of the given filename, then takes away the leading 'backend_'.""" return os.path.splitext(fname)[0][8:] # get the directory where the backends live backends_dir = os.path.dirname(matplotlib.backends.__file__) # filter all files in that directory to identify all files which provide a backend backend_fnames = filter(is_backend_module, os.listdir(backends_dir)) backends = [backend_fname_formatter(fname) for fname in backend_fnames] print backends 
+6
May 7 '11 at 10:12
source share

Here you can also find documentation for several backends:

http://matplotlib.org/api/index_backend_api.html

only a few backends are listed on the pages, some of them do not have proper documentation:

 matplotlib.backend_bases matplotlib.backends.backend_gtkagg matplotlib.backends.backend_qt4agg matplotlib.backends.backend_wxagg matplotlib.backends.backend_pdf matplotlib.dviread matplotlib.type1font 
+3
Feb 18 '13 at 12:37
source share

You can see the following folder for a list of possible backends ...

 /Library/Python/2.6/site-packages/matplotlib/backends /usr/lib64/Python2.6/site-packages/matplotlib/backends 
+2
Feb 23 2018-11-23T00:
source share

You can pretend to have set the wrong backend argument, then it will return you a ValueError with a list of valid matplotlib backends, for example:

Input data:

 import matplotlib matplotlib.use('WRONG_ARG') 

Exit:

 ValueError: Unrecognized backend string 'test': valid strings are ['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt 5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template'] 
0
Jun 23 '19 at 4:54
source share



All Articles