client-side image maps

I would like to use matplotlib to make a simple client-side
image map for a web page. I have a scatter plot and I would
like mouseovers/clicks to show information about the given
point.

I started with the webapp_demo.py from the most recent
release (0.80). There was a small bug

% python webapp_demo.py
Traceback (most recent call last):
   File "webapp_demo.py", line 87, in ?
     make_fig()
   File "webapp_demo.py", line 64, in make_fig
     x = nx.rand(100)
AttributeError: 'module' object has no attribute 'rand'

Here's my bandage hack

import random
def rand(n):
   return nx.array([random.random() for i in range(n)])
nx.rand = rand

I then added some code after the PNG is written which
generates an basic html file from the coordinates using
what I thought was the correct transformation from
data space to image space.

     canvas.print_figure('webapp.png', dpi=150)
     f = open("webapp.html", "w")
     f.write('''<HTML><BODY><img src="webapp.png" ismap usemap="#plot">
<map name="plot">
''')
     t = c.get_transform()
     xys = t.seq_xy_tups(c.get_verts())
     for i, xy in enumerate(xys):
       f.write('<area shape="circle" coords="%d,%d,2" href="%d">\n' %
               (xy[0], xy[1], i))
     f.write("</map>\n</html>")

The HTML output starts with the following

<HTML><BODY><img src="webapp.png" ismap usemap="#plot">
<map name="plot">
<area shape="circle" coords="393,286,2" href="0">
<area shape="circle" coords="381,285,2" href="1">
<area shape="circle" coords="222,271,2" href="2">
<area shape="circle" coords="238,300,2" href="3">

There are two things wrong with the code. First, the
transformed coordinates aren't at the same scale as
the generated PNG. The PNG size depends on the dpi
setting but the x/y coordinates aren't affected by
that setting.

Second, I think I have the y direction swapped. Where
do I get the current image size, and for that matter
how do I set the output image size?

          Andrew
          dalke@...579...

A few weeks ago I asked about using matplotlib to make a
simple client-side image map for a web page.

I since figured out my problem. I wrote an set of essays on
it. The most relevant is at
   http://www.dalkescientific.com/writings/diary/archive/2005/04/24/interactive_html.html

          Andrew
          dalke@...579...