## matplotlib-users

 [Matplotlib-users] post-processing, HTML 's, element geometry From: Jack Andrews - 2005-05-31 03:56:57 ```hi there, matplotlib is great! i want to create bar-charts, save to PNG and produce an HTML map to be used over the PNG. something like this: so that when the user clicks on bar1 or bar2 of the chart, the appropriate URL is loaded. is there a way to get the coordinates of the bar from matlab, or do i have to do some optical-chart-recognition? (or make my own little charting package) thanks, jack. ```
 Re: [Matplotlib-users] post-processing, HTML 's, element geometry From: John Hunter - 2005-05-31 13:37:29 ```>>>>> "Jack" == Jack Andrews writes: Jack> hi there, matplotlib is great! i want to create bar-charts, Jack> save to PNG and produce an HTML map to be used over the PNG. Jack> something like this: Jack> href="1.html"> href="2.html"> Jack> so that when the user clicks on bar1 or bar2 of the chart, Jack> the appropriate URL is loaded. Jack> is there a way to get the coordinates of the bar from Jack> matlab, or do i have to do some optical-chart-recognition? Jack> (or make my own little charting package) Andrew Dalke has recently written a nice tutorial on how to use matplotlib to make clickable html images - http://www.dalkescientific.com/writings/diary/archive/2005/04/24/interactive_html.html As for your specific question about the extent of the bars, you can get them as follows; note that in matplotlib 0,0 is the bottom, left of the figure. You may need to correct for this if html click maps assume 0 is the top of the image. Andrew's tutorial covers this a bit import matplotlib matplotlib.use('Agg') import pylab as p import matplotlib.numerix as nx dpi = 80 f = p.figure(dpi=dpi) # figure width and height in pixels figw, figh = f.get_width_height() x = nx.arange(5) y = x**2 patches = p.bar(x,y) for patch in patches: l,b,w,h = patch.get_window_extent().get_bounds() print l,b,w,h p.savefig('somefile', dpi=dpi) Note that matplotlib enables you to have a different dpi setting for the "display" figure and the saved figure, so to make sure they are the same, pass the same dpi to figure and savefig. If you need to correct for the figure y origin at top, you can use figh which is the height of the figure. Hope this helps. If at all possible, please resist the urge to write your own plotting package :-) Trust me, I know it is hard to resist. If matplotlib can't do something you need, pester us a bit and we'll try to add it. Else python will die from the curse of too many plotting packages.... JDH ```