How to add a new backend?

Hello,
we want to add a new backend for some specific XML format.

Can I find somewhere a sort of How-To documentation about the required
steps?

In particular I want to avoid modifying the matplotlib installation which
resides in system directories which not every user has access to. Is it
possible to extend the backend base class to a full backend implementation
located below my home directory, and then have matplotlib use this backend?

How would I tell matplotlib about my new class, and how do I prepare things
so that a simple
matplotlib.use('MyXML')
will plot in our file format?

Thanks
Jason

···


View this message in context: http://www.nabble.com/How-to-add-a-new-backend--tp20089848p20089848.html
Sent from the matplotlib - devel mailing list archive at Nabble.com.

Hello,
we want to add a new backend for some specific XML format.

Can I find somewhere a sort of How-To documentation about the required
steps?

In particular I want to avoid modifying the matplotlib installation which
resides in system directories which not every user has access to. Is it
possible to extend the backend base class to a full backend implementation
located below my home directory, and then have matplotlib use this backend?

How would I tell matplotlib about my new class, and how do I prepare things
so that a simple
matplotlib.use('MyXML')
will plot in our file format?

If you set the backend to "module://my_backend" where my_backend.py is
a backend in your PYTHONPATH, matplotlib will load it and use it.

You can also use the -d flag, eg

  > python simple_ploy.py -d file://my_backend

Let us know how it goes!

JDH

···

On Tue, Oct 21, 2008 at 8:04 AM, jason_h <hadleyjason@...656...> wrote:

If you set the backend to "module://my_backend" where my_backend.py is
a backend in your PYTHONPATH, matplotlib will load it and use it.

And yes, I forgot to mention, "use" works as well

  import matplotlib
  matplotlib.use('module://my_backend')

and the syntax for the -d flag was wrong in my last email (it is
"module://" not "file://"), it should read::

  > python simple_ploy.py -d module://my_backend

JDH

···

On Tue, Oct 21, 2008 at 8:40 AM, John Hunter <jdh2358@...149...> wrote:

John Hunter-4 wrote:

  import matplotlib
  matplotlib.use('module://my_backend')

Unfortunately that doesn't work for me. I get a "ValueError: Unrecognized
backend string "module://mybackend"" in rcsetup.py. Any other suggestions?
Matplotlib ist version 0.98.3.

Here is the output:
$ python
Python 2.5.1 (r251:54863, Mar 7 2008, 03:41:45)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import matplotlib
matplotlib.use("module://mybackend")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/matplotlib/__init__.py", line 809,
in use
    rcParams['backend'] = name
  File "/usr/lib/python2.5/site-packages/matplotlib/__init__.py", line 588,
in __setitem__
    cval = self.validate[key](val)
  File "/usr/lib/python2.5/site-packages/matplotlib/rcsetup.py", line 49, in
__call__
    % (self.key, s, self.valid.values()))
ValueError: Unrecognized backend string "module://mybackend": valid strings
are ['ps', 'Qt4Agg', 'FltkAgg', 'GTKAgg', 'agg', 'cairo', 'GTK', 'GTKCairo',
'WXAgg', 'TkAgg', 'QtAgg', 'svg', 'pdf', 'CocoaAgg', 'emf', 'gdk',
'template', 'WX']

Neither does the -d option work. "python --help" says:
...
-d : debug output from parser (also PYTHONDEBUG=x)
...

How is this option related to plotting backends?

Thanks
Jason

···

On Tue, Oct 21, 2008 at 8:40 AM, John Hunter <jdh2358@...149...> wrote:

--
View this message in context: http://www.nabble.com/How-to-add-a-new-backend--tp20089848p20091178.html
Sent from the matplotlib - devel mailing list archive at Nabble.com.

Hmm, strangely, the rcsetup function was reverted and as you note, is
broken, I just fixed it in svn to respect the flag, and tested with
the use directive and -d, both of which worked for me. If you don't
want to update to svn HEAD, you can edit rcsetup.py on your system and
replace::

    validate_backend = ValidateInStrings('backend', all_backends,
ignorecase=True)

with::

    _validate_standard_backends = ValidateInStrings('backend',
all_backends, ignorecase=True)
    def validate_backend(s):
        if s.startswith('module://'): return s
        else: return _validate_standard_backends(s)

Should work...

JDH

···

On Tue, Oct 21, 2008 at 9:14 AM, jason_h <hadleyjason@...656...> wrote:

Unfortunately that doesn't work for me. I get a "ValueError: Unrecognized
backend string "module://mybackend"" in rcsetup.py. Any other suggestions?
Matplotlib ist version 0.98.3.

John Hunter-4 wrote:

    _validate_standard_backends = ValidateInStrings('backend',
all_backends, ignorecase=True)
    def validate_backend(s):
        if s.startswith('module://'): return s
        else: return _validate_standard_backends(s)

Should work...

Thanks. Now matplotlib.use('module://...') works.
(The -d option still doesn't, but I don't need it.)

Jason

···

--
View this message in context: http://www.nabble.com/How-to-add-a-new-backend--tp20089848p20092273.html
Sent from the matplotlib - devel mailing list archive at Nabble.com.