From: Julius L. <jul...@gm...> - 2006-02-21 16:54:58
|
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 =3D 150 fig =3D figure(num=3D1,figsize=3D(6,4),dpi=3Ddots,facecolor=3D'w') ax =3D fig.add_subplot(111) pl =3D ax.plot(range(0,10),range(0,10),'b-') box =3D ax.axvspan(3,6,fc=3D'm',alpha=3D0.5) fig.savefig('test.png',dpi=3Ddots) img_height =3D fig.get_figheight() * dots b_verts =3D box.get_verts() #image maps use left-x,left-y,right-x,right-y verts =3D [(b_verts[1][0],b_verts[1][1]),(b_verts[3][0],b_verts[3][1])] tverts =3D box.get_transform().seq_xy_tups(verts) #image maps have y=3D0 on top tverts =3D (tverts[0][0],img_height-tverts[0][1],tverts[1][0],img_height-tv= erts[1][1]) file =3D open('test.html','w') file.write('''<HTML> <HEAD> <TITLE>Image Map Test</TITLE> </HEAD> <BODY> <map name=3D"map"> <area shape=3D"rect" coords=3D"%d,%d,%d,%d" href=3D"http://www.google.com= "> </map> <img border=3D2 src=3D"./test.png" usemap=3D"#map"> </BODY> </HTML> ''' % tverts ) file.close() |