Encoding again

In some of my plots I show month names as axes labels.

When I run this on a machine in "French" (i.e. on Win XP changing the Settings - Regional and Language settings" to French the labels don't show correctly if there is an accented character in there e.g. "d�c".

I changed the line 256 in dates.py (matplotlib 0.8) from:

return dt.strftime(fmt)

to:

return unicode(dt.strftime(fmt), 'iso-8859-1')

Obviously this is not a correct fix as it will only work in some situations.

I tried to use sys.getdefaultencoding(), instead of hard coding 'iso-8859-1', but on my machine it returns "ascii".

Any suggestions on how to handle this correctly will be very appreciated.

See you
Werner

Hi All,

I think I found a solution for dates.py which could work for everyone.

Instead of hardcoding the encoding I "import locale" and get the default encoding from it. I have tested it on both Win XP and 2000 and it works for me, i.e. in English locale I get "Dec" and in French locale I get "d�c." etc. without the correction I would get a graphic sign for the "�".

To test just use "locale.setlocale(locale.LC_ALL, 'fr')"

Just noticed that "avr" is not correctly aligned with the other month, but that's for another day.

The only two changes needed to dates.py are:

import locale

and change

return dt.strftime(fmt)

to

return unicode(dt.strftime(fmt), locale.getpreferredencoding())

Best regards
Werner

Werner F. Bruhin wrote:

···

In some of my plots I show month names as axes labels.

When I run this on a machine in "French" (i.e. on Win XP changing the Settings - Regional and Language settings" to French the labels don't show correctly if there is an accented character in there e.g. "d�c".

I changed the line 256 in dates.py (matplotlib 0.8) from:

return dt.strftime(fmt)

to:

return unicode(dt.strftime(fmt), 'iso-8859-1')

Obviously this is not a correct fix as it will only work in some situations.

I tried to use sys.getdefaultencoding(), instead of hard coding 'iso-8859-1', but on my machine it returns "ascii".

Any suggestions on how to handle this correctly will be very appreciated.

See you
Werner

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

I haven't had any feedback on my original post for this, would be great if someone could verify that this works in other configurations, e.g. on Linux or other language then French which uses accented characters in the month name abreviations.

The problem is that if a plot shows month names as axes labels.

When I run this on a machine in "French" (i.e. on Win XP changing the
Settings - Regional and Language settings" to French the labels don't
show correctly if there is an accented character in there e.g. "d�c".

The solution which works for me is to "import locale" and get the default encoding from it. I have tested it on both Win XP and 2000 and it works for me, i.e. in English locale I get "Dec" and in French locale I get "d�c." etc. without the correction I would get a graphic sign for the "�".

The only two changes needed to dates.py are:

import locale

and change

return dt.strftime(fmt)

to

return unicode(dt.strftime(fmt), locale.getpreferredencoding())

Best regards
Werner

Werner F. Bruhin wrote: