Exporting accents in EPS

Hi,

I’m trying to export a MAtplotlib figure which has some axes labels, such as ‘coût’.
The problème is that the generated eps is corrupted because of these accents. Is there a way to generate an acceptable eps file ?

Matthieu

···


French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher

Can you provide an example of your code? Often, it is a matter of configuring/using Python correctly to indicate accents. Is the problem only with EPS or other backends as well?

Cheers,
Mike

Matthieu Brucher wrote:

···

Hi,

I'm trying to export a MAtplotlib figure which has some axes labels, such as 'co�t'.
The probl�me is that the generated eps is corrupted because of these accents. Is there a way to generate an acceptable eps file ?

Matthieu
--
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

No problem with the png backend.

I tried with Latex for the accent, but it didn’t work :
Traceback (most recent call last):
File “”, line 1, in
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/pyplot.py”, line 265, in draw
get_current_fig_manager().canvas.draw()
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/backends/backend_wx.py”, line 953, in draw
self.figure.draw(self.renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/figure.py”, line 612, in draw
for a in self.axes: a.draw(renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/axes.py”, line 1342, in draw
a.draw(renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/axis.py”, line 593, in draw
tick.draw(renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/axis.py”, line 170, in draw
if self.label1On: self.label1.draw(renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/text.py”, line 775, in draw
Text.draw(self, renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/text.py”, line 327, in draw
self._fontproperties, angle)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/backend_bases.py”, line 383, in draw_tex
raise NotImplementedError

I just did :

import pylab as pl
pl.plot([1, 2, 3], [1, 2, 3])
pl.xlabel(‘éè’)
pl.show()

and the ps file is corrupted :frowning:

Matthieu

2008/2/1, Michael Droettboom <mdroe@…86…>:

···

Can you provide an example of your code? Often, it is a matter of
configuring/using Python correctly to indicate accents. Is the problem
only with EPS or other backends as well?

Cheers,
Mike

Matthieu Brucher wrote:

Hi,

I’m trying to export a MAtplotlib figure which has some axes labels,
such as ‘coût’.
The problème is that the generated eps is corrupted because of these

accents. Is there a way to generate an acceptable eps file ?

Matthieu

French PhD student
Website : http://matthieu-brucher.developpez.com/

Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher



This SF.net email is sponsored by: Microsoft

Defy all challenges. Microsoft® Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/



Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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

French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92

LinkedIn : http://www.linkedin.com/in/matthieubrucher

Some additional information : it does not work with the pdf backend and with the svg one, the accents are corrupted (I tried to export utf8 encoded labels).
I’m using pycrust, BTW. But I don’t know how to change the default encoding (the display is correct but not the saved image).

Matthieu

2008/2/1, Matthieu Brucher <matthieu.brucher@…83…287…>:

···

No problem with the png backend.

I tried with Latex for the accent, but it didn’t work :
Traceback (most recent call last):
File “”, line 1, in
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/pyplot.py”, line 265, in draw

get_current_fig_manager().canvas.draw()

File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/backends/backend_wx.py”, line 953, in draw
self.figure.draw(self.renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/figure.py”, line 612, in draw

for a in self.axes: a.draw(renderer)

File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/axes.py”, line 1342, in draw
a.draw(renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/axis.py”, line 593, in draw

tick.draw(renderer)

File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/axis.py”, line 170, in draw
if self.label1On: self.label1.draw(renderer)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/text.py”, line 775, in draw

Text.draw(self, renderer)

File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/text.py”, line 327, in draw
self._fontproperties, angle)
File “/home/brucher/local//lib/python2.5/site-packages/matplotlib/backend_bases.py”, line 383, in draw_tex

raise NotImplementedError

I just did :

import pylab as pl
pl.plot([1, 2, 3], [1, 2, 3])
pl.xlabel(‘éè’)
pl.show()

and the ps file is corrupted :frowning:

Matthieu

2008/2/1, Michael Droettboom <mdroe@…86…>:

Can you provide an example of your code? Often, it is a matter of
configuring/using Python correctly to indicate accents. Is the problem
only with EPS or other backends as well?

Cheers,
Mike

Matthieu Brucher wrote:

Hi,

I’m trying to export a MAtplotlib figure which has some axes labels,
such as ‘coût’.
The problème is that the generated eps is corrupted because of these

accents. Is there a way to generate an acceptable eps file ?

Matthieu

French PhD student
Website : http://matthieu-brucher.developpez.com/

Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92

LinkedIn : http://www.linkedin.com/in/matthieubrucher



This SF.net email is sponsored by: Microsoft

Defy all challenges. Microsoft® Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/



Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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

French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92

LinkedIn : http://www.linkedin.com/in/matthieubrucher


French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92

LinkedIn : http://www.linkedin.com/in/matthieubrucher

Unicode in Python is tricky. It is explained in gory detail here:

    http://www.amk.ca/python/howto/unicode

But to save you the trouble of reading the whole thing, unless you're an i18n geek like me, here's my list of recommendations to (somewhat) reliably get non-ASCII characters to work in Python. There are other ways, (and people tend to have their own opinions about this, mostly based on the capabilities of their editors).

   1. "Non-ASCII" means any codepoint that is greater than 127. Your local encoding may have characters with accents in the range 128-255, but that is *not* ASCII.

   2. Always use Unicode literals for anything that contains non-ASCII characters (by prefixing the literal with a 'u'). It is never a good idea to put non-ASCII characters in a regular 8-bit Python string -- they do not "remember" their encoding, and the application has no way to know how to interpret it.

   3. Always declare an encoding at the top of the file, e.g.:

  # -*- coding: utf-8 -*-

      (I like utf-8 for generality, but you could use any of the encodings that Python understands, see here: http://docs.python.org/lib/standard-encodings.html)

   4. Make sure your editor is correctly saving the file in that specified encoding. This is perhaps the hardest step because editors all handle it a little differently. Some editors have an option somewhere to set the encoding that files are saved in. Others may automatically understand the "coding" comment line in the file. (Same goes for any terminal emulator you may be using for interactive plotting.)

If you can't get step 4 to work successfully, you can write Unicode strings in Python using only ASCII characters using the "\u0000" escape sequence.

  u"Flamb\u00e9e"

(Here, the Unicode code point for e with accent-aigu is 00E9).

So, following all of the above, the attached works fine for me with .eps output on 0.91.2. (There were various Unicode issues in 0.90.x that were fixed.) If it still doesn't work for you, please let us know.

Cheers,
Mike

Matthieu Brucher wrote:

accent.py (147 Bytes)

···

No problem with the png backend.

I tried with Latex for the accent, but it didn't work :
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/pyplot.py", line 265, in draw
    get_current_fig_manager().canvas.draw()
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/backends/backend_wx.py", line 953, in draw
    self.figure.draw(self.renderer)
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/figure.py", line 612, in draw
    for a in self.axes: a.draw(renderer)
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/axes.py", line 1342, in draw
    a.draw(renderer)
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/axis.py", line 593, in draw
    tick.draw(renderer)
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/axis.py", line 170, in draw
    if self.label1On: self.label1.draw(renderer)
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/text.py", line 775, in draw
    Text.draw(self, renderer)
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/text.py", line 327, in draw
    self._fontproperties, angle)
  File "/home/brucher/local//lib/python2.5/site-packages/matplotlib/backend_bases.py", line 383, in draw_tex
    raise NotImplementedError

I just did :

import pylab as pl
pl.plot([1, 2, 3], [1, 2, 3])
pl.xlabel('��')
pl.show()

and the ps file is corrupted :frowning:

Matthieu

2008/2/1, Michael Droettboom <mdroe@…86… <mailto:mdroe@…86…>>:

    Can you provide an example of your code? Often, it is a matter of
    configuring/using Python correctly to indicate accents. Is the problem
    only with EPS or other backends as well?

    Cheers,
    Mike

    Matthieu Brucher wrote:
     > Hi,
     >
     > I'm trying to export a MAtplotlib figure which has some axes labels,
     > such as 'co�t'.
     > The probl�me is that the generated eps is corrupted because of these
     > accents. Is there a way to generate an acceptable eps file ?
     >
     > Matthieu
     > --
     > French PhD student
     > Website : http://matthieu-brucher.developpez.com/
     > Blogs : http://matt.eifelle.com and
    http://blog.developpez.com/?blog=92
     > LinkedIn : http://www.linkedin.com/in/matthieubrucher
     >

     >
    ------------------------------------------------------------------------
     >
    -------------------------------------------------------------------------
     > This SF.net email is sponsored by: Microsoft
     > Defy all challenges. Microsoft(R) Visual Studio 2008.
     > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
     >
    ------------------------------------------------------------------------
     >
     > _______________________________________________
     > Matplotlib-users mailing list
     > Matplotlib-users@lists.sourceforge.net
    <mailto:Matplotlib-users@lists.sourceforge.net>
     > https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

--
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

  1. Make sure your editor is correctly saving the file in that
    specified encoding. This is perhaps the hardest step because editors

all handle it a little differently. Some editors have an option
somewhere to set the encoding that files are saved in. Others may
automatically understand the “coding” comment line in the file. (Same

goes for any terminal emulator you may be using for interactive plotting.)

If you can’t get step 4 to work successfully, you can write Unicode
strings in Python using only ASCII characters using the “\u0000” escape

sequence.

    u"Flamb\u00e9e"

(Here, the Unicode code point for e with accent-aigu is 00E9).

I think this may be the obvious problem (I don’t how to change the encoding in pycrust :|)

So, following all of the above, the attached works fine for me with .eps
output on 0.91.2. (There were various Unicode issues in 0.90.x that

were fixed.) If it still doesn’t work for you, please let us know.

I’ll try this (I think the 3D stuff still works with this version, doesn’t it ?)

Matthieu

···

French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92

LinkedIn : http://www.linkedin.com/in/matthieubrucher

Matthieu Brucher wrote:

       4. Make sure your editor is correctly saving the file in that
    specified encoding. This is perhaps the hardest step because editors
    all handle it a little differently. Some editors have an option
    somewhere to set the encoding that files are saved in. Others may
    automatically understand the "coding" comment line in the file. (Same
    goes for any terminal emulator you may be using for interactive
    plotting.)

    If you can't get step 4 to work successfully, you can write Unicode
    strings in Python using only ASCII characters using the "\u0000" escape
    sequence.

            u"Flamb\u00e9e"

    (Here, the Unicode code point for e with accent-aigu is 00E9).

I think this may be the obvious problem (I don't how to change the encoding in pycrust :|)

Could be. As I say, getting your editor to behave can be tricky.

    So, following all of the above, the attached works fine for me with .eps
    output on 0.91.2. (There were various Unicode issues in 0.90.x that
    were fixed.) If it still doesn't work for you, please let us know.

I'll try this (I think the 3D stuff still works with this version, doesn't it ?)

Yes. 0.91.x should be the same as 0.90.x in that regard.

···

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

2008/2/1, Matthieu Brucher <matthieu.brucher@…287…>:

  1. Make sure your editor is correctly saving the file in that

specified encoding. This is perhaps the hardest step because editors

all handle it a little differently. Some editors have an option
somewhere to set the encoding that files are saved in. Others may
automatically understand the “coding” comment line in the file. (Same

goes for any terminal emulator you may be using for interactive plotting.)

If you can’t get step 4 to work successfully, you can write Unicode
strings in Python using only ASCII characters using the “\u0000” escape

sequence.

    u"Flamb\u00e9e"

(Here, the Unicode code point for e with accent-aigu is 00E9).

I think this may be the obvious problem (I don’t how to change the encoding in pycrust :|)

So, following all of the above, the attached works fine for me with .eps

output on 0.91.2. (There were various Unicode issues in 0.90.x that

were fixed.) If it still doesn’t work for you, please let us know.

I’ll try this (I think the 3D stuff still works with this version, doesn’t it ?)

Seems to work fine know, thanks for the tips :wink:

Matthieu

···


French PhD student
Website : http://matthieu-brucher.developpez.com/

Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher