On Tue, Sep 16, 2008 at 9:00 PM, John Hunter <[EMAIL PROTECTED]> wrote:
> Oops, wait, I answered too fast. The figure.dpi *was* already used in > the cache key and the renderer.dpi, which I just added, is not > guaranteed to exist (depending on the backend). I need to figure out > why the figure.dpi in the cache key is not sufficient .... OK, I see what is going on. Actually, nothing is broken (feature not bug, though admittedly confusing). In savefig, the renderer saves the display dpi, sets the savefig dpi on the figure and renderer (as necessary) instances, draws the figure, and then restores the display dpi. Outside of savefig therefore, all you see when calling get_window_extent is the display dpi. What you need to do is hook into the drawing so you can get the window extent when the canvas is drawn by savefig, when the savefig dpi is set. The script below shows that before and after savefig, you get the display dpi extent, but in the draw event you get the savefig dpi. If this is too onerous and you know you will be using an image backend, just set the rc figure and savefig dpi to be the same. import matplotlib as mpl mpl.use('agg') import matplotlib.pyplot as plt fig = plt.figure() t = plt.text(0.5, 0.6, 'testing') print 'before save window extent', t.get_window_extent().extents def ondraw(event): print 'on draw window extent', t.get_window_extent().extents fig.canvas.mpl_connect('draw_event', ondraw) fig.savefig('/tmp/t150.png', dpi=150) print 'after save window extent', t.get_window_extent().extents plt.show() JDH ------------------------------------------------------------------------- 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