Errors with PDF (TeX-string) output using Qt4Agg

<PHobson@...2792...> writes:

  File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 1378, in draw_mathtext
    self.file.output(self.encode_string(unichr(num), fonttype), Op.show)
ValueError: unichr() arg not in range(0x10000) (narrow Python build)

Right, IPython really had mangled the traceback. That looks like the
mathtext parser is outputting some characters outside the Basic
Multilingual Plane. Could you try the following:

python -i c:\GDAG2009\python\pyTest.py -d pdf

Then when the error occurs, you should be at a Python prompt. Then type
(or just copy and paste from here - be careful with the first two lines,
since any exception will cause Python to forget the existing traceback):

from pdb import pm
pm()
p fontname, fontsize, num, symbol_name
p s, width, height, descent, glyphs, rects, used_characters
p fonttype, global_fonttype

It might work to set pdf.fonttype to 3 in matplotlibrc, but even if it
helps, it would be useful to find the root of this problem.

···

--
Jouni K. Seppänen

What is your mathtext.fontset setting? If it's stixsans, then it is possible that mathtext would produce codepoints outside of the BMP (this is due to the way the STIX fonts are encoded). Unfortunately, the standard Python builds for Windows don't support characters in this range.

There might actually be a work around possible in the PDF backend -- but it will have to involve encoding Unicode characters without using Python unicode objects. I'm looking into a patch now.

Cheers,
Mike

···

On 10/12/2009 04:17 PM, Jouni K. Seppänen wrote:

<PHobson@...2792...> writes:

   File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 1378, in draw_mathtext
     self.file.output(self.encode_string(unichr(num), fonttype), Op.show)
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
     

Right, IPython really had mangled the traceback. That looks like the
mathtext parser is outputting some characters outside the Basic
Multilingual Plane. Could you try the following:

python -i c:\GDAG2009\python\pyTest.py -d pdf

Then when the error occurs, you should be at a Python prompt. Then type
(or just copy and paste from here - be careful with the first two lines,
since any exception will cause Python to forget the existing traceback):

from pdb import pm
pm()
p fontname, fontsize, num, symbol_name
p s, width, height, descent, glyphs, rects, used_characters
p fonttype, global_fonttype

It might work to set pdf.fonttype to 3 in matplotlibrc, but even if it
helps, it would be useful to find the root of this problem.

Jouni,

I found the error! I got bored this past weekend and changed my mathtext.fontset to 'stixsans' just to see hopw it would look -- and then forgot about it. Changing that value back to 'cm' let's my original code and pyTest.py run without errors.

I really appreciate your help with this and all of the other insight I've gained from the regular contributers to this list.

Many thanks,
-paul

Regardless, here's my command line output with stixsans as my mathtext.fontset:
C:\Python25>python -i c:\gdag2009\python\pyTest.py -d pdf
Traceback (most recent call last):
  File "c:\gdag2009\python\pyTest.py", line 12, in <module>
    pl.savefig('some_math.pdf')
  File "C:\Python25\Lib\site-packages\matplotlib\pyplot.py", line 356, in savefig
    return fig.savefig(*args, **kwargs)
  File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 1032, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 144, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 1476, in print_figure
    **kwargs)
  File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 1334, in print_pdf
    return pdf.print_pdf(*args, **kwargs)
  File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 2025, in print_pdf
    self.figure.draw(renderer)
  File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 773, in draw
    for a in self.axes: a.draw(renderer)
  File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1735, in draw
    a.draw(renderer)
  File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
    draw(artist, renderer, *kl)
  File "C:\Python25\Lib\site-packages\matplotlib\axis.py", line 757, in draw
    self.label.draw(renderer)
  File "C:\Python25\Lib\site-packages\matplotlib\text.py", line 565, in draw
    ismath=ismath)
  File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 1516, in draw_text
    if ismath: return self.draw_mathtext(gc, x, y, s, prop, angle)
  File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 1378, in draw_mathtext
    self.file.output(self.encode_string(unichr(num), fonttype), Op.show)
ValueError: unichr() arg not in range(0x10000) (narrow Python build)

from pdb import pm
pm()

c:\python25\lib\site-packages\matplotlib\backends\backend_pdf.py(1378)draw_mathtext()

-> self.file.output(self.encode_string(unichr(num), fonttype), Op.show)
(Pdb) p fontname, fontsize, num, symbol_name
('C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralItalic.ttf', 7.0, 120378, 'u1D63A')
(Pdb) p s, width, height, descent, glyphs, rects, used_characters
('some math: \\\\tau\_\{y\}', 72.0, 11.0, 3.0, [(0.0, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\V
era.ttf', 10.0, 115, 's'), (5.2099609375, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf',
10.0, 111, 'o'), (11.328125, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 109,
'm'), (21.0693359375, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 101, 'e'), (2
7.2216796875, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 32, 'space'), (30.400
390625, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 109, 'm'), (40.1416015625,
3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 97, 'a'), (46.26953125, 3.40625, 'C
:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 116, 't'), (50.1904296875, 3.40625, 'C:\\Pytho
n25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 104, 'h'), (56.5283203125, 3.40625, 'C:\\Python25\\lib
\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 58, 'colon'), (59.8974609375, 3.40625, 'C:\\Python25\\lib\\sit
e-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 32, 'space'), (63.076171875, 3.40625, 'C:\\Python25\\lib\\site-pack
ages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXNonUniIta.ttf', 10.0, 57835, 'uniE1EB'), (67.75616455078125, 2.046875, 'C:\\Python25\\
lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralItalic.ttf', 7.0, 120378, 'u1D63A')], , {'C:\\Python25\\lib\\si
te-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralItalic.ttf': ('C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\f
onts\\ttf\\STIXGeneralItalic.ttf', set([120378])), 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf':
('C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', set([32, 97, 101, 104, 109, 111, 115, 116, 58]))
, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXNonUniIta.ttf': ('C:\\Python25\\lib\\site-packages\\mat
plotlib\\mpl-data\\fonts\\ttf\\STIXNonUniIta.ttf', set([57835]))})
(Pdb) p fonttype, global_fonttype
(42, 42)

···

-----Original Message-----
From: Jouni K. Seppänen [mailto:jks@…397…]
Sent: Monday, October 12, 2009 1:18 PM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Errors with PDF (TeX-string) output
using Qt4Agg

<PHobson@...2792...> writes:

> File "C:\Python25\Lib\site-
packages\matplotlib\backends\backend_pdf.py", line 1378, in
draw_mathtext
> self.file.output(self.encode_string(unichr(num), fonttype),
Op.show)
> ValueError: unichr() arg not in range(0x10000) (narrow Python build)

Right, IPython really had mangled the traceback. That looks like the
mathtext parser is outputting some characters outside the Basic
Multilingual Plane. Could you try the following:

python -i c:\GDAG2009\python\pyTest.py -d pdf

Then when the error occurs, you should be at a Python prompt. Then
type
(or just copy and paste from here - be careful with the first two
lines,
since any exception will cause Python to forget the existing
traceback):

from pdb import pm
pm()
p fontname, fontsize, num, symbol_name
p s, width, height, descent, glyphs, rects, used_characters
p fonttype, global_fonttype

It might work to set pdf.fonttype to 3 in matplotlibrc, but even if it
helps, it would be useful to find the root of this problem.

--
Jouni K. Seppänen
Jouni Seppänen

----------------------------------------------------------------------
--------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart
your
developing skills, take BlackBerry mobile applications to market and
stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Mike,

Thanks for the reply. I found that I had (on a whim) set my mathtext.fontset to stixsans and then forgot about it. Returning that value to cm fixes my issues. In short, I'm all squared away now. Thanks!

Paul M. Hobson

···

-----Original Message-----
From: Michael Droettboom [mailto:mdroe@…86…]
Sent: Monday, October 12, 2009 1:38 PM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Errors with PDF (TeX-string) output
using Qt4Agg

On 10/12/2009 04:17 PM, Jouni K. Seppänen wrote:
> <PHobson@...2792...> writes:
>
>
>> File "C:\Python25\Lib\site-
packages\matplotlib\backends\backend_pdf.py", line 1378, in
draw_mathtext
>> self.file.output(self.encode_string(unichr(num), fonttype),
Op.show)
>> ValueError: unichr() arg not in range(0x10000) (narrow Python
build)
>>
> Right, IPython really had mangled the traceback. That looks like the
> mathtext parser is outputting some characters outside the Basic
> Multilingual Plane. Could you try the following:
>
> python -i c:\GDAG2009\python\pyTest.py -d pdf
>
> Then when the error occurs, you should be at a Python prompt. Then
type
> (or just copy and paste from here - be careful with the first two
lines,
> since any exception will cause Python to forget the existing
traceback):
>
> from pdb import pm
> pm()
> p fontname, fontsize, num, symbol_name
> p s, width, height, descent, glyphs, rects, used_characters
> p fonttype, global_fonttype
>
> It might work to set pdf.fonttype to 3 in matplotlibrc, but even if
it
> helps, it would be useful to find the root of this problem.
>
>
What is your mathtext.fontset setting? If it's stixsans, then it is
possible that mathtext would produce codepoints outside of the BMP
(this
is due to the way the STIX fonts are encoded). Unfortunately, the
standard Python builds for Windows don't support characters in this
range.

There might actually be a work around possible in the PDF backend --
but
it will have to involve encoding Unicode characters without using
Python
unicode objects. I'm looking into a patch now.

Cheers,
Mike

----------------------------------------------------------------------
--------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart
your
developing skills, take BlackBerry mobile applications to market and
stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks. On further investigation, I was reminded that stixsans (or anything not in the BMP) doesn't work with Type 42 fonts. The way the PDF spec forces you to deal with them, if it's even possible, is really hairy. So to solve your problem you can either a) not use stixsans, or b) use Type 3 fonts. We should document this somewhere.

In any case, we should still fix the crash bug on narrow (e.g. Windows) Python builds, so the behavior of "no characters printed" is at least the same on all environments. We should probably add some Type 3 vs. Type 42 font regression tests as well.

Mike

···

On 10/12/2009 04:43 PM, PHobson@...2792... wrote:

Jouni,

I found the error! I got bored this past weekend and changed my mathtext.fontset to 'stixsans' just to see hopw it would look -- and then forgot about it. Changing that value back to 'cm' let's my original code and pyTest.py run without errors.

I really appreciate your help with this and all of the other insight I've gained from the regular contributers to this list.

Many thanks,
-paul

Regardless, here's my command line output with stixsans as my mathtext.fontset:
C:\Python25>python -i c:\gdag2009\python\pyTest.py -d pdf
Traceback (most recent call last):
   File "c:\gdag2009\python\pyTest.py", line 12, in<module>
     pl.savefig('some_math.pdf')
   File "C:\Python25\Lib\site-packages\matplotlib\pyplot.py", line 356, in savefig
     return fig.savefig(*args, **kwargs)
   File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 1032, in savefig
     self.canvas.print_figure(*args, **kwargs)
   File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 144, in print_figure
     FigureCanvasAgg.print_figure(self, *args, **kwargs)
   File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 1476, in print_figure
     **kwargs)
   File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line 1334, in print_pdf
     return pdf.print_pdf(*args, **kwargs)
   File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 2025, in print_pdf
     self.figure.draw(renderer)
   File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
     draw(artist, renderer, *kl)
   File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 773, in draw
     for a in self.axes: a.draw(renderer)
   File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
     draw(artist, renderer, *kl)
   File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1735, in draw
     a.draw(renderer)
   File "C:\Python25\Lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper
     draw(artist, renderer, *kl)
   File "C:\Python25\Lib\site-packages\matplotlib\axis.py", line 757, in draw
     self.label.draw(renderer)
   File "C:\Python25\Lib\site-packages\matplotlib\text.py", line 565, in draw
     ismath=ismath)
   File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 1516, in draw_text
     if ismath: return self.draw_mathtext(gc, x, y, s, prop, angle)
   File "C:\Python25\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 1378, in draw_mathtext
     self.file.output(self.encode_string(unichr(num), fonttype), Op.show)
ValueError: unichr() arg not in range(0x10000) (narrow Python build)
   

from pdb import pm
pm()
         

c:\python25\lib\site-packages\matplotlib\backends\backend_pdf.py(1378)draw_mathtext()
     

-> self.file.output(self.encode_string(unichr(num), fonttype), Op.show)
(Pdb) p fontname, fontsize, num, symbol_name
('C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralItalic.ttf', 7.0, 120378, 'u1D63A')
(Pdb) p s, width, height, descent, glyphs, rects, used_characters
('some math: \\\\tau\_\{y\}', 72.0, 11.0, 3.0, [(0.0, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\V
era.ttf', 10.0, 115, 's'), (5.2099609375, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf',
  10.0, 111, 'o'), (11.328125, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 109,
'm'), (21.0693359375, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 101, 'e'), (2
7.2216796875, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 32, 'space'), (30.400
390625, 3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 109, 'm'), (40.1416015625,
3.40625, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 97, 'a'), (46.26953125, 3.40625, 'C
:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 116, 't'), (50.1904296875, 3.40625, 'C:\\Pytho
n25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 104, 'h'), (56.5283203125, 3.40625, 'C:\\Python25\\lib
\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 58, 'colon'), (59.8974609375, 3.40625, 'C:\\Python25\\lib\\sit
e-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', 10.0, 32, 'space'), (63.076171875, 3.40625, 'C:\\Python25\\lib\\site-pack
ages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXNonUniIta.ttf', 10.0, 57835, 'uniE1EB'), (67.75616455078125, 2.046875, 'C:\\Python25\\
lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralItalic.ttf', 7.0, 120378, 'u1D63A')], , {'C:\\Python25\\lib\\si
te-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralItalic.ttf': ('C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\f
onts\\ttf\\STIXGeneralItalic.ttf', set([120378])), 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf':
  ('C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf', set([32, 97, 101, 104, 109, 111, 115, 116, 58]))
, 'C:\\Python25\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXNonUniIta.ttf': ('C:\\Python25\\lib\\site-packages\\mat
plotlib\\mpl-data\\fonts\\ttf\\STIXNonUniIta.ttf', set([57835]))})
(Pdb) p fonttype, global_fonttype
(42, 42)

-----Original Message-----
From: Jouni K. Seppänen [mailto:jks@…397…]
Sent: Monday, October 12, 2009 1:18 PM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Errors with PDF (TeX-string) output
using Qt4Agg

<PHobson@...2792...> writes:

   File "C:\Python25\Lib\site-
       

packages\matplotlib\backends\backend_pdf.py", line 1378, in
draw_mathtext
     

     self.file.output(self.encode_string(unichr(num), fonttype),
       

Op.show)
     

ValueError: unichr() arg not in range(0x10000) (narrow Python build)
       

Right, IPython really had mangled the traceback. That looks like the
mathtext parser is outputting some characters outside the Basic
Multilingual Plane. Could you try the following:

python -i c:\GDAG2009\python\pyTest.py -d pdf

Then when the error occurs, you should be at a Python prompt. Then
type
(or just copy and paste from here - be careful with the first two
lines,
since any exception will cause Python to forget the existing
traceback):

from pdb import pm
pm()
p fontname, fontsize, num, symbol_name
p s, width, height, descent, glyphs, rects, used_characters
p fonttype, global_fonttype

It might work to set pdf.fonttype to 3 in matplotlibrc, but even if it
helps, it would be useful to find the root of this problem.

--
Jouni K. Seppänen
Jouni Seppänen

----------------------------------------------------------------------
--------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart
your
developing skills, take BlackBerry mobile applications to market and
stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
     

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options