2011-02-23 3 views

Répondre

31

Vous pouvez accéder aux listes

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

le troisième étant la concaténation des deux premiers. Si je lis correctement le code source, ces listes sont codées en dur, et ne vous disent pas quels backends sont réellement utilisables. Il y a également

matplotlib.rcsetup.validate_backend(name) 

mais cela ne vérifie également que la liste codée en dur.

2

Vous pouvez regarder le dossier suivant pour obtenir une liste des backends possibles ...

/Library/Python/2.6/site-packages/matplotlib/backends 
/usr/lib64/Python2.6/site-packages/matplotlib/backends 
7

Il y a la liste codée en dur mentionné par Sven, mais de trouver tous les back-end qui Matplotlib peut utiliser (basé sur l'implémentation actuelle pour la mise en place d'un backend) le dossier matplotlib/backends peut être inspecté.

Le code suivant fait ceci:

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 
36

Voici une modification du script affiché précédemment. Il trouve tous les backends supportés, les valide et mesure leur fps. Sur Mac OS X, il se bloque python quand il vient à tkAgg, utilisez à vos propres risques et périls;)

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 :(") 
+1

Refusé comme une réponse plus complète (je peux être partial parce que c'est juste ce dont j'avais besoin aussi bien). – fredbaba

+0

Les scripts se bloquent pour moi (https://gist.github.com/palmstrom/6039823), mais fonctionnent bien lorsqu'ils sont exécutés sous Spyder IDE. – Palmstrom

+0

Quels sont les résultats typiques de ce benchmark? Les numéros FPS? – rc0r

3

Vous pouvez également consulter la documentation pour quelques backends ici:

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

les listes de pages juste quelques backends, certains d'entre eux n'ont pas une documentation appropriée:

matplotlib.backend_bases 
matplotlib.backends.backend_gtkagg 
matplotlib.backends.backend_qt4agg 
matplotlib.backends.backend_wxagg 
matplotlib.backends.backend_pdf 
matplotlib.dviread 
matplotlib.type1font 
+2

Le lien solitaire est considéré comme une mauvaise réponse (voir [suppression de faq #]) car il n'a aucune signification en soi et ** la ressource cible n'est pas garantie d'être vivante dans le futur **. [Il serait préférable] (http://meta.stackexchange.com/q/8259) d'inclure les parties essentielles de la réponse ici, et de fournir le lien pour référence. – j0k

+0

Je suis désolé, je pensais que les réponses ci-dessus couvraient le sujet, mais devrait avoir le lien comme référence, c'est pourquoi j'ai posté. Je ne veux pas de mal, je suis un noob. – Leandro

Questions connexes