How to convert resolution -> (inches, dpi)

is there a formula which will always convert a image

    > resolution (x pixels by y pixles) to inches, dpi I'm
    > assuming that there are some contraints to how high and
    > low dpi can go. How and what are those contraints.

There are no formal constraints. If you set the dpi too high you eill
eventually run out of memory. I suppose dpi<1 is undefined :-).

Typical screen dpis are 72 and 96. If you want the screen size the be
accurate in inches, you need to make the dpi setting correspond to the
actual pixels per inch on the monitor. matplotlib does not currently
support different horizontal and vertical dpis (many monitors have
different resolutions in the horizontal and vertical dimensions). It
wouldn't be hard to add, but last time I suggested it on the list
noone was interested.

Here is an example to set the figure size in inches given pixel
dimensions and dpi

    from __future__import division # do float division

    pixw, pixh = 640, 680
    dpi = 96
    winch = pixw/dpi # width in inches is pixel width / dpi
    hinch = pixh/dpi # height in inches is pixel height / dpi
    fig = figure(figsize=(winch, hinch), dpi=dpi)

This is what backend_gtk does after a figure resize - I have to conver
the pixel dimensions to inches.

You can change an existing figure's size, if necessary, with

  fig.set_figsize_inches(winch, hinch)

Hope this helps,
JDH