dpi settings are still a source of confusion.  Suppose one wants to get 
the bounding boxes of strings in a png file, for use as clickable 
regions on a web site.  Just use the get_window_extent() method of each 
text object after it has been drawn with savefig, right?  Wrong! The 
gotcha is that get_window_extent() is always based on the "ordinary" 
dpi, not on the "savefig" dpi.


In [1]:import matplotlib as mpl
In [2]:mpl.use('agg')
In [4]:import matplotlib.pyplot as plt
In [5]:fig = plt.figure()
In [6]:t = plt.text(0.5, 0.6, 'testing')
In [7]:fig.savefig('/tmp/t50.png', dpi=50)
In [9]:t.get_window_extent().extents
Out[9]:array([ 328.      ,  278.4     ,  356.046875,  287.4     ])
In [10]:fig.savefig('/tmp/t150.png', dpi=150)
In [11]:t.get_window_extent().extents
Out[11]:array([ 328.   ,  278.4  ,  411.875,  302.4  ])

In [12]:t._renderer.dpi
Out[12]:150

I find this very confusing--the _renderer.dpi is not being used by 
get_window_extent().  Is this the intended behavior?  If so, I would 
like to at least add a note to that effect to the get_window_extent 
docstring.

The obvious workaround is to always use
"fig.savefig('figname.png', dpi=rcParams['figure.dpi'])
in this sort of application.

Eric

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to