tk, pylab and unicode

Hello,

I'm a french user and I'm trying to put an '�' into a pylab title.
My locales and fully utf-8 and the code is the following under ipthon:
import pylab
a="�"
pylab.plot([1])
pylab.title(a)

raises the error :
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)

Is it a bug or a I doing something wrong? I'm using up to date pylab svn with the tk backend.

The prolem is that only the tk backend is fully functionnal on my box. HTe gtk one never shows the buttons (debian up to date sid).

Xavier

···

--
############################################
Xavier Gnata
CRAL - Observatoire de Lyon
9, avenue Charles Andr�
69561 Saint Genis Laval cedex
Phone: +33 4 78 86 85 28
Fax: +33 4 78 86 83 86
E-mail: gnata@...419...
############################################

Ok it is a bug because matplotlib.rc('text',usetex=False) and then it works.
But is always fails using matplotlib.rc('text',usetex=True)...side effect...

Xavier

···

Hello,

I'm a french user and I'm trying to put an '�' into a pylab title.
My locales and fully utf-8 and the code is the following under ipthon:
import pylab
a="�"
pylab.plot([1])
pylab.title(a)

raises the error :
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)

Is it a bug or a I doing something wrong? I'm using up to date pylab svn with the tk backend.

The prolem is that only the tk backend is fully functionnal on my box. HTe gtk one never shows the buttons (debian up to date sid).

Xavier

--
############################################
Xavier Gnata
CRAL - Observatoire de Lyon
9, avenue Charles Andr�
69561 Saint Genis Laval cedex
Phone: +33 4 78 86 85 28
Fax: +33 4 78 86 83 86
E-mail: gnata@...419...
############################################

Xavier Gnata wrote:

Hello,

I'm a french user and I'm trying to put an '�' into a pylab title.
My locales and fully utf-8 and the code is the following under ipthon:
import pylab
a="�"
pylab.plot([1])
pylab.title(a)

raises the error :
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)

Have you tried using a Unicode string as input? e.g.

a = u"�"

That works for me, though it stops at the LaTeX step because I'm missing some LaTeX packages.

Is it a bug or a I doing something wrong? I'm using up to date pylab svn with the tk backend.

The prolem is that only the tk backend is fully functionnal on my box. HTe gtk one never shows the buttons (debian up to date sid).

The Tk backend is treating your input string as Latin-1, not UCS, which is the same for codepoints < 255, so you got lucky.

There are probably a few of these encoding bugs in various backends that should probably be worked through.

Cheers,
Mike

Hello,

I'm a french user and I'm trying to put an '�' into a pylab title.
My locales and fully utf-8 and the code is the following under ipthon:
import pylab
a="�"
pylab.plot([1])
pylab.title(a)

raises the error :
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
    
Have you tried using a Unicode string as input? e.g.

a = u"�"

That works for me, though it stops at the LaTeX step because I'm missing some LaTeX packages.

Is it a bug or a I doing something wrong? I'm using up to date pylab svn with the tk backend.

The prolem is that only the tk backend is fully functionnal on my box. HTe gtk one never shows the buttons (debian up to date sid).
    
The Tk backend is treating your input string as Latin-1, not UCS, which is the same for codepoints < 255, so you got lucky.

There are probably a few of these encoding bugs in various backends that should probably be worked through.

Cheers,
Mike

With a = u"�" I get no error but also nothing as a title. No strange characters. Nothing.

Xavier

···

--
############################################
Xavier Gnata
CRAL - Observatoire de Lyon
9, avenue Charles Andr�
69561 Saint Genis Laval cedex
Phone: +33 4 78 86 85 28
Fax: +33 4 78 86 83 86
E-mail: gnata@...419...
############################################

Xavier Gnata wrote:

With a = u"�" I get no error but also nothing as a title. No strange characters. Nothing.

This is working for me with the latest svn version, as well as 0.90.1, on Linux with Python 2.5 and Tcl/Tk 8.4.

There are other things that could be going wrong. The encoding of your terminal may not match your default encoding in your Python interpreter. If you're using Linux, can you please send the output of:

> locale
> python -c "import locale; print locale.getpreferredencoding()"

If all is working correctly, you should get the following in your python interpreter:

>>> a = u"�"
>>> ord(a)
233

If you're using an editor (i.e. not using pylab interactively), you'll need to make sure that it is outputting in the correct encoding, and respecting the

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

line. Recent versions of emacs do this, but I can't really speak for others.

I have attached a test script that works for me. It even includes some Greek characters as Unicode which work if you select a Unicode font with those characters.

Cheers,
Mike

unicode.py (127 Bytes)

I should clarify, I have this working with the TkAgg backend and "text.usetex : False". If "text.usetex : True", I can't confirm or deny whether that works since I don't have a proper LaTeX ucs.sty setup here to test with.

As an aside, if you're looking to Gtk as a way around this, the Gtk backend uses the same rendering pipeline for text when text.usetex is True, so it likely will produce the same result.

Cheers,
Mie

Michael Droettboom wrote:

···

Xavier Gnata wrote:

With a = u"�" I get no error but also nothing as a title. No strange characters. Nothing.

This is working for me with the latest svn version, as well as 0.90.1, on Linux with Python 2.5 and Tcl/Tk 8.4.

There are other things that could be going wrong. The encoding of your terminal may not match your default encoding in your Python interpreter. If you're using Linux, can you please send the output of:

> locale
> python -c "import locale; print locale.getpreferredencoding()"

If all is working correctly, you should get the following in your python interpreter:

>>> a = u"�"
>>> ord(a)
233

If you're using an editor (i.e. not using pylab interactively), you'll need to make sure that it is outputting in the correct encoding, and respecting the

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

line. Recent versions of emacs do this, but I can't really speak for others.

I have attached a test script that works for me. It even includes some Greek characters as Unicode which work if you select a Unicode font with those characters.

Cheers,
Mike

I installed the necessary stuff in my LaTeX installation from here:

    http://www.unruh.de/DniQ/latex/unicode/

and it's now working even when usetex is on.

It would be great to figure out why it's broken for you.

Do you get any error output from LaTeX?

Cheers,
Mike

Michael Droettboom wrote:

···

I should clarify, I have this working with the TkAgg backend and "text.usetex : False". If "text.usetex : True", I can't confirm or deny whether that works since I don't have a proper LaTeX ucs.sty setup here to test with.

As an aside, if you're looking to Gtk as a way around this, the Gtk backend uses the same rendering pipeline for text when text.usetex is True, so it likely will produce the same result.

Cheers,
Mie

Michael Droettboom wrote:

Xavier Gnata wrote:

With a = u"�" I get no error but also nothing as a title. No strange characters. Nothing.

This is working for me with the latest svn version, as well as 0.90.1, on Linux with Python 2.5 and Tcl/Tk 8.4.

There are other things that could be going wrong. The encoding of your terminal may not match your default encoding in your Python interpreter. If you're using Linux, can you please send the output of:

> locale
> python -c "import locale; print locale.getpreferredencoding()"

If all is working correctly, you should get the following in your python interpreter:

>>> a = u"�"
>>> ord(a)
233

If you're using an editor (i.e. not using pylab interactively), you'll need to make sure that it is outputting in the correct encoding, and respecting the

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

line. Recent versions of emacs do this, but I can't really speak for others.

I have attached a test script that works for me. It even includes some Greek characters as Unicode which work if you select a Unicode font with those characters.

Cheers,
Mike

ok look like a missing font on my box. Will see...

Xavier

···

I installed the necessary stuff in my LaTeX installation from here:

    http://www.unruh.de/DniQ/latex/unicode/

and it's now working even when usetex is on.

It would be great to figure out why it's broken for you.

Do you get any error output from LaTeX?

Cheers,
Mike

Michael Droettboom wrote:
  

I should clarify, I have this working with the TkAgg backend and "text.usetex : False". If "text.usetex : True", I can't confirm or deny whether that works since I don't have a proper LaTeX ucs.sty setup here to test with.

As an aside, if you're looking to Gtk as a way around this, the Gtk backend uses the same rendering pipeline for text when text.usetex is True, so it likely will produce the same result.

Cheers,
Mie

Michael Droettboom wrote:
    

Xavier Gnata wrote:
      

With a = u"�" I get no error but also nothing as a title. No strange characters. Nothing.
        

This is working for me with the latest svn version, as well as 0.90.1, on Linux with Python 2.5 and Tcl/Tk 8.4.

There are other things that could be going wrong. The encoding of your terminal may not match your default encoding in your Python interpreter. If you're using Linux, can you please send the output of:

> locale
> python -c "import locale; print locale.getpreferredencoding()"

If all is working correctly, you should get the following in your python interpreter:

>>> a = u"�"
>>> ord(a)
233

If you're using an editor (i.e. not using pylab interactively), you'll need to make sure that it is outputting in the correct encoding, and respecting the

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

line. Recent versions of emacs do this, but I can't really speak for others.

I have attached a test script that works for me. It even includes some Greek characters as Unicode which work if you select a Unicode font with those characters.

Cheers,
Mike
      
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
############################################
Xavier Gnata
CRAL - Observatoire de Lyon
9, avenue Charles Andr�
69561 Saint Genis Laval cedex
Phone: +33 4 78 86 85 28
Fax: +33 4 78 86 83 86
E-mail: gnata@...419...
############################################