Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Webagg changes #1878

merged 4 commits into from Apr 12, 2013


None yet
2 participants

pelson commented Apr 2, 2013

Some refactoring work on the WebAgg backend.

Key features:

  • you can now run the backend with a url prefix (i.e. it is now possible to run the service under*, if you so desired)
  • objectified the JS figure (and associated web socket) so that more than one figure can exist on the same page
  • there is an "all figures" landing page which handles keyboard & mouse focus appropriately
  • the creation of the appropriate HTML elements is now easier due to the mpl_interface.js factory functions

I've been testing this out with the following code:

import matplotlib

import matplotlib.pyplot as plt


plt.bar(range(10), range(10))


I still have some other changes I'd like to make to the WebAgg architecture, but I think this is a reasonable first step which adds some nice, self contained, functionality.


pelson commented Apr 2, 2013

Note: one of the changes I was referring to was to JSLint the javascript - I'd be happy to do that here before anybody sets their eyes on my (probably poor) javascript. Shout if you'd like that to happen now, otherwise, I'll probably defer the linting to my next PR ;-)

@mdboom mdboom commented on the diff Apr 2, 2013

@@ -443,52 +503,69 @@ def send_image(self):
diff.encode('base64').replace('\n', ''))
- def __init__(self):
+ def __init__(self, url_prefix=''):
+ if url_prefix:
+ assert url_prefix[0] == '/' and url_prefix[-1] != '/', \
+ 'url_prefix must start with a "/" and not end with one.'

mdboom Apr 2, 2013


Should we instead just add the prefix / if it's not there?


pelson Apr 2, 2013


Both are fine, it's something most people will never use (I don't propose making in an RcParam) - its for follow on applications (which I plan to look at in the next couple of weeks) for which I will want to implement a namespace. The one thing in favour of this approach is that there is no ambiguity - if you get it wrong then you will get a decent message about it, but I can also see the other side of the argument too (if you can check that something is wrong, you can fix it programatically for the user...)


mdboom commented Apr 2, 2013

This is great. I think the objectification work you've done to allow multiple figures on the same page will come in very handy when this gets integrated with IPython notebook. (I hope to hash out a plan for that at Scipy if I can get all the experts in the room together...)

I am getting this message when I run this (haven't really looked into why):

ERROR:root:Uncaught exception GET /favicon.ico (
HTTPRequest(protocol='http', host='', method='GET', uri='/favicon.ico', version='HTTP/1.1', remote_ip='', body='', headers={'Accept-Charset': 'UTF-8,*;q=0.5', 'Connection': 'keep-alive', 'Accept-Language': 'en-US,en;q=0.8', 'Accept-Encoding': 'gzip,deflate,sdch', 'Host': '', 'Accept': '*/*', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31'})
Traceback (most recent call last):
  File "/home/mdboom/python/lib/python2.7/site-packages/tornado-2.4.1-py2.7.egg/tornado/web.py", line 1042, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/backends/backend_webagg.py", line 379, in get
    with open(os.path.join(self._mpl_dirs['images'],
AttributeError: 'FavIcon' object has no attribute '_mpl_dirs'

pelson commented Apr 2, 2013

Fixed the favicon directory problem in 786a6b4.


pelson commented Apr 12, 2013

@mdboom - any actions on this? I'm keen to reduce my number of PRs 😄


mdboom commented Apr 12, 2013

Now that the favicon thing is fixed, I think this is good to go.

@mdboom mdboom added a commit that referenced this pull request Apr 12, 2013

@mdboom mdboom Merge pull request #1878 from pelson/webagg_changes
Webagg changes

@mdboom mdboom merged commit 9e477b3 into matplotlib:master Apr 12, 2013

1 check passed

default The Travis build passed

pelson commented Apr 12, 2013

Cool. Thanks @mdboom. I'm going to start up a conversation on the ipython-dev mailing list in the next week or so to start thinking about notebook magic. I'd like to be able to use it in a talk at SciPy 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment