This is a bug in that matplotlib is not reading the preferred encoding correctly, because doing so has undesired side effects in some cases. An easy workaround is to add the following to the top of your script (before importing matplotlib):
import locale locale.setlocale(locale.LC_ALL, '') Note, you will also need to select a font that has Cyrillic characters. The default font shipped with matplotlib "Vera Sans" does not, but you can use its more-Unicode-complete sibling "DejaVu Sans" (installed on most Linux systems by default). Interestingly, another use had a similar problem quite recently. The following branch of matplotlib may also fix your problem: https://github.com/mdboom/matplotlib/tree/locale_formatting To test this, you would need to build it from source, and then set the rcParam "axes.formatter.use_locale" to True. Cheers, Mike On 08/01/2011 12:23 AM, Alexey Uimanov wrote: > Here the code > #!/usr/bin/env python > > from pylab import figure, show > from matplotlib.dates import AutoDateLocator, AutoDateFormatter, > drange, DateFormatter > import datetime > import random > > dates = drange(datetime.datetime(2010, 1, 1), datetime.datetime(2010, > 12,31), datetime.timedelta(days = 1)) > opens = map(lambda a: random.random(), dates) > > fig = figure() > ax = fig.add_subplot(111) > ax.plot_date(dates, opens, '-') > > majloc = AutoDateLocator() > majform = AutoDateFormatter(majloc) > > ax.xaxis.set_major_locator(majloc) > ax.xaxis.set_major_formatter(majform) > ax.autoscale_view() > ax.grid(True) > fig.autofmt_xdate() > show() > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > It is just the same code as date_demo1.py from examples directory with > some modifications > My current locale is ru_RU.UTF-8 and i want plot the date ruller along > X axis in format of my locale, with russian names of months. > I can not do this because of this error when printing the chart > Traceback (most recent call last): > File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_gtk.py", > line 394, in expose_event > self._render_figure(self._pixmap, w, h) > File > "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", > line 75, in _render_figure > FigureCanvasAgg.draw(self) > File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", > line 394, in draw > self.figure.draw(self.renderer) > File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line > 55, in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "/usr/lib/python2.7/site-packages/matplotlib/figure.py", line > 798, in draw > func(*args) > File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line > 55, in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "/usr/lib/python2.7/site-packages/matplotlib/axes.py", line 1946, in > draw > a.draw(renderer) > File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line > 55, in draw_wrapper > draw(artist, renderer, *args, **kwargs) > File "/usr/lib/python2.7/site-packages/matplotlib/axis.py", line 971, in > draw > tick_tups = [ t for t in self.iter_ticks()] > File "/usr/lib/python2.7/site-packages/matplotlib/axis.py", line > 907, in iter_ticks > majorLabels = [self.major.formatter(val, i) for i, val in > enumerate(majorLocs)] > File "/usr/lib/python2.7/site-packages/matplotlib/dates.py", line > 486, in __call__ > return self._formatter(x, pos) > File "/usr/lib/python2.7/site-packages/matplotlib/dates.py", line > 336, in __call__ > return self.strftime(dt, self.fmt) > File "/usr/lib/python2.7/site-packages/matplotlib/dates.py", line > 362, in strftime > return cbook.unicode_safe(dt.strftime(fmt)) > File "/usr/lib/python2.7/site-packages/matplotlib/cbook.py", line > 41, in unicode_safe > else: return unicode(s, preferredencoding) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position > 0: ordinal not in range(128) > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > When lauching this with LANG=C everythig works but datetime prints in > english locale. > Version of matplotlib is 1.0.1 > What am i doing wrong ? > > ------------------------------------------------------------------------------ > Got Input? Slashdot Needs You. > Take our quick survey online. Come on, we don't ask for help often. > Plus, you'll get a chance to win $100 to spend on ThinkGeek. > http://p.sf.net/sfu/slashdot-survey > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Michael Droettboom Science Software Branch Space Telescope Science Institute Baltimore, Maryland, USA ------------------------------------------------------------------------------ Got Input? Slashdot Needs You. Take our quick survey online. Come on, we don't ask for help often. Plus, you'll get a chance to win $100 to spend on ThinkGeek. http://p.sf.net/sfu/slashdot-survey _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users