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:
> <map name="a"> <area shape="rect" coords="20,90,25,30"
> href="1.html"> <area shape="rect" coords="40,60,45,30"
> href="2.html"> </map> <img src="a.png" usemap="#a">
> 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)
Andrew Dalke has recently written a nice tutorial on how to use
matplotlib to make clickable html images -
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 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()
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