URLs embedded in PNG or JPEG

my question is what transform do I use to convert verts to

    > pixel coordinates? ax.get_transform() does not work.
    > Should I use pl.get_transform?

"Does not work" is not very descriptive :frowning:

Yes, you should use the polygon transform

You might want to look at the "draw" method of the
matplotlib.patches.Polygon class to see how it gets the data into
pixel coords

        verts = self.get_verts()
        tverts = self._transform.seq_xy_tups(verts)

Thus all you need to do outside the class is

  trans = pl.get_transform()
  verts = pl.get_verts()
  tverts = trans.seq_xy_tups(verts)

Should work...

The documentation for the matplotlib.transforms module is decent, if
you want to take a look

  http://matplotlib.sourceforge.net/matplotlib.transforms.html

JDH

For the benefit of the list, below is a working script that makes a
simple plot with a patch element, outputs the plot to a png, and
outputs an html file that contains an image map so that the patch
element is clickable.

Thanks for all the help,

Julius

#!/usr/bin/env python

from pylab import *

dots = 150
fig = figure(num=1,figsize=(6,4),dpi=dots,facecolor='w')
ax = fig.add_subplot(111)
pl = ax.plot(range(0,10),range(0,10),'b-')
box = ax.axvspan(3,6,fc='m',alpha=0.5)

fig.savefig('test.png',dpi=dots)

img_height = fig.get_figheight() * dots

b_verts = box.get_verts()

#image maps use left-x,left-y,right-x,right-y
verts = [(b_verts[1][0],b_verts[1][1]),(b_verts[3][0],b_verts[3][1])]

tverts = box.get_transform().seq_xy_tups(verts)

#image maps have y=0 on top
tverts = (tverts[0][0],img_height-tverts[0][1],tverts[1][0],img_height-tverts[1][1])

file = open('test.html','w')
file.write('''<HTML>
<HEAD>
  <TITLE>Image Map Test</TITLE>
</HEAD>
<BODY>
<map name="map">
  <area shape="rect" coords="%d,%d,%d,%d" href="http://www.google.com">
</map>
<img border=2 src="./test.png" usemap="#map">
</BODY>
</HTML> ''' % tverts )

file.close()