bounding box functionality with text() function

I'm having a problem with the bbox keyword to the text() function. The code below, for me, results in one postscript file that looks fine, but the PNG file has letters outside of the bounding box for most of the words I plot.

I'm using matplotlib '0.98pre' on Mac OS X.

import matplotlib
matplotlib.use('agg')
from pylab import *

x = array([6,7,8,9,10])
y = array([6,7,8,9,10])
fig = figure()
plot(x,y,'rx')
hold('on')
fontdict2 = {'fontweight':'light',
             'color': 'k',
             'fontsize':9}
words = ['Hi','Goodbye','What''s this','Aloha','So long, farewell']
for i in range(0,len(x)):
    tx = x[i]
    ty = y[i]
    word = words[i]
    text(tx,ty,word,fontdict2,bbox={'facecolor':'w'})

savefig('textplot.eps')
savefig('textplot.png')
close(fig)

···

--
------------------------------------------------------
Michael Hearne
mhearne@...924...
(303) 273-8620
USGS National Earthquake Information Center
1711 Illinois St. Golden CO 80401
Senior Software Engineer
Synergetics, Inc.
------------------------------------------------------

Interesting. When I plot it on my screen it looks correct with a *Agg
GUI backend. But when I save it (either from the GUI or using
savefig) it has the problem you describe. This suggests to me that
either some cached information or something is not getting notified of
the different default dpi in savefig. I'll look into it. Since PS is
dpi independent, it would not affect it.

Thanks for the reminder.

JDH

···

On Mon, Jun 9, 2008 at 3:35 PM, Michael Hearne <mhearne@...924...> wrote:

savefig('textplot.eps')
savefig('textplot.png')
close(fig)

Well, my diagnosis wasn't correct, but I fixed the problem. In the
caching of the text layout, we were not taking into account the
different renderers in the cache key. Since PS has a nominal dpi
setting that is ignored by postscript, the differences in dpi were not
getting picked up in the layout cache. The solution I implemented was
to simply add the renderer id to the property tuple used for caching.
Fixed in svn r5470.

JDH

···

On Wed, Jun 11, 2008 at 10:14 AM, John Hunter <jdh2358@...287...> wrote:

Interesting. When I plot it on my screen it looks correct with a *Agg
GUI backend. But when I save it (either from the GUI or using
savefig) it has the problem you describe. This suggests to me that
either some cached information or something is not getting notified of
the different default dpi in savefig. I'll look into it. Since PS is
dpi independent, it would not affect it.

John - Thanks for the quick fix. I'm having a separate issue now with an EPS file being generated (using savefig() again) that appears to be invalid (can't display it in OS X Preview, or convert to PDF with ps2pdf). Unfortunately, the code that creates this particular file is rather involved, and hard to replicate with one simple script.

If I send the offending EPS file (it's 1.4 MB zipped), is it possible to tell from that what the problem is?

The errors from ps2pdf are:
Error: /undefined in --get--
Operand stack:
   true --dict:43/43(ro)(L)-- .notdef
Execution stack:
   %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1905 1 3 %oparray_pop 1904 1 3 %oparray_pop --nostringval-- 1888 1 3 %oparray_pop 1771 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- %finish_show --nostringval-- --nostringval-- 5 4 0 --nostringval-- (pdf_text_enum_t) %op_show_continue --nostringval--
Dictionary stack:
   --dict:1144/1684(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dict:61/112(L)-- --dict:20/25(ro)(L)--
Current allocation mode is local
Last OS error: 2
Current file position is 996122
GPL Ghostscript 8.61: Unrecoverable error, exit code 1

--Mike

John Hunter wrote:

···

On Wed, Jun 11, 2008 at 10:14 AM, John Hunter <jdh2358@...287...> wrote:

Interesting. When I plot it on my screen it looks correct with a *Agg
GUI backend. But when I save it (either from the GUI or using
savefig) it has the problem you describe. This suggests to me that
either some cached information or something is not getting notified of
the different default dpi in savefig. I'll look into it. Since PS is
dpi independent, it would not affect it.
    
Well, my diagnosis wasn't correct, but I fixed the problem. In the
caching of the text layout, we were not taking into account the
different renderers in the cache key. Since PS has a nominal dpi
setting that is ignored by postscript, the differences in dpi were not
getting picked up in the layout cache. The solution I implemented was
to simply add the renderer id to the property tuple used for caching.
Fixed in svn r5470.

JDH
  
--
------------------------------------------------------
Michael Hearne
mhearne@...924...
(303) 273-8620
USGS National Earthquake Information Center
1711 Illinois St. Golden CO 80401
Senior Software Engineer
Synergetics, Inc.
------------------------------------------------------

If you can find a way to create a minimal script, that would be better, because then we can verify the fix.

But barring anything else, seeing the .eps might help.

Cheers,
Mike

Michael Hearne wrote:

···

John - Thanks for the quick fix. I'm having a separate issue now with an EPS file being generated (using savefig() again) that appears to be invalid (can't display it in OS X Preview, or convert to PDF with ps2pdf). Unfortunately, the code that creates this particular file is rather involved, and hard to replicate with one simple script.

If I send the offending EPS file (it's 1.4 MB zipped), is it possible to tell from that what the problem is?

The errors from ps2pdf are:
Error: /undefined in --get--
Operand stack:
   true --dict:43/43(ro)(L)-- .notdef
Execution stack:
   %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1905 1 3 %oparray_pop 1904 1 3 %oparray_pop --nostringval-- 1888 1 3 %oparray_pop 1771 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- %finish_show --nostringval-- --nostringval-- 5 4 0 --nostringval-- (pdf_text_enum_t) %op_show_continue --nostringval--
Dictionary stack:
   --dict:1144/1684(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)-- --dict:61/112(L)-- --dict:20/25(ro)(L)--
Current allocation mode is local
Last OS error: 2
Current file position is 996122
GPL Ghostscript 8.61: Unrecoverable error, exit code 1

--Mike

John Hunter wrote:
  

On Wed, Jun 11, 2008 at 10:14 AM, John Hunter <jdh2358@...287...> wrote:

Interesting. When I plot it on my screen it looks correct with a *Agg
GUI backend. But when I save it (either from the GUI or using
savefig) it has the problem you describe. This suggests to me that
either some cached information or something is not getting notified of
the different default dpi in savefig. I'll look into it. Since PS is
dpi independent, it would not affect it.
    

Well, my diagnosis wasn't correct, but I fixed the problem. In the
caching of the text layout, we were not taking into account the
different renderers in the cache key. Since PS has a nominal dpi
setting that is ignored by postscript, the differences in dpi were not
getting picked up in the layout cache. The solution I implemented was
to simply add the renderer id to the property tuple used for caching.
Fixed in svn r5470.

JDH
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA