From 519322ff68f5bc3caacfb884a35a9895cd4d38df Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 26 Sep 2011 11:01:09 -0400 Subject: [PATCH 1/2] Pass Unicode strings to matplotlib, since some of them are > 128. --- examples/pylab_examples/font_table_ttf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 examples/pylab_examples/font_table_ttf.py diff --git a/examples/pylab_examples/font_table_ttf.py b/examples/pylab_examples/font_table_ttf.py old mode 100644 new mode 100755 index 6400efb0bb3d..0a80c535dce4 --- a/examples/pylab_examples/font_table_ttf.py +++ b/examples/pylab_examples/font_table_ttf.py @@ -32,7 +32,7 @@ for ccode, glyphind in codes: if ccode>=256: continue r,c = divmod(ccode,16) - s = chr(ccode) + s = unichr(ccode) chars[r][c] = s From df428f0a2959655a2c8aa43f283ad6f9c2567a63 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 26 Sep 2011 11:01:48 -0400 Subject: [PATCH 2/2] Display a more helpful error message when an 8-bit non-ascii string is passed to matplotlib. --- lib/matplotlib/cbook.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index c3d8ff596394..cd1dc68e197e 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1820,7 +1820,11 @@ def __call__(self, key): def is_math_text(s): # Did we find an even number of non-escaped dollar signs? # If so, treat is as math text. - s = unicode(s) + try: + s = unicode(s) + except UnicodeDecodeError: + raise ValueError( + "matplotlib display text must have all code points < 128 or use Unicode strings") dollar_count = s.count(r'$') - s.count(r'\$') even_dollars = (dollar_count > 0 and dollar_count % 2 == 0)