[Matplotlib-users] how can i use utf-8 or just how can i plot the datetime in local settings ?
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
[Matplotlib-users] close gtk2 figure without main_quit() call
I am writing gtk2 application on python, I need to plot a chart in separate window and i just use this code def matplot_print(self, print_values): """\brief print data by matplotlib and shw the figure \param print_values [(name - is a string, [(datetime, value)] - is a list of data to plot)] - list of charts to plot """ fig = plt.figure() ax = fig.add_subplot(111) names = map(lambda a: a[0], print_values) lines = map(lambda chart: ax.plot_date(map(lambda chd: chd[0], chart[1]), map(lambda chy: chy[1], chart[1]), '-'), print_values) plt.figlegend(lines, names, 'upper left') 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() fig.show() The figure is showing and everything works before closing the window of figure. It seems that figure call gtk.main_quit() when closing it's window. How to override this behaviour ? -- BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] segfault in matplotlib
here is the sample code "embedding_in_gtk2.py" 6 import gtk 7 8 from matplotlib.figure import Figure 9 from numpy import arange, sin, pi 10 11 # uncomment to select /GTK/GTKAgg/GTKCairo 12 #from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas 13 from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas 14 #from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas 15 16 # or NavigationToolbar for classic 17 #from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar 18 from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar 19 20 21 win = gtk.Window() 22 win.connect("destroy", lambda x: gtk.main_quit()) 23 win.set_default_size(400,300) 24 win.set_title("Embedding in GTK") 25 26 vbox = gtk.VBox() 27 win.add(vbox) 28 29 fig = Figure(figsize=(5,4), dpi=100) 30 import pudb 31 pudb.set_trace() 32 ax = fig.add_subplot(111) 33 t = arange(0.0,3.0,0.01) 34 s = sin(2*pi*t) 35 36 ax.plot(t,s) 37 38 39 canvas = FigureCanvas(fig) # a gtk.DrawingArea 40 vbox.pack_start(canvas) 41 toolbar = NavigationToolbar(canvas, win) 42 vbox.pack_start(toolbar, False, False) 43 44 45 win.show_all() 46 gtk.main() on line 36 error segfault. Here is the gdb session Starting program: /usr/bin/python2.7 embedding_in_gtk2.py [Thread debugging using libthread_db enabled] Program received signal SIGSEGV, Segmentation fault. 0x7fffeda71594 in __cxa_allocate_exception () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/libstdc++.so.6 #0 0x7fffeda71594 in __cxa_allocate_exception () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/libstdc++.so.6 #1 0x7fffe4830164 in py_to_agg_transformation_matrix(_object*, bool) () from /usr/lib64/python2.7/site-packages/matplotlib/_path.so #2 0x7fffe483addb in _path_module::update_path_extents(Py::Tuple const&) () from /usr/lib64/python2.7/site-packages/matplotlib/_path.so #3 0x7fffe4841ad8 in Py::ExtensionModule<_path_module>::invoke_method_varargs(void*, Py::Tuple const&) () from /usr/lib64/python2.7/site-packages/matplotlib/_path.so #4 0x7fffe482b54d in method_varargs_call_handler () from /usr/lib64/python2.7/site-packages/matplotlib/_path.so #5 0x77b09a7b in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0 #6 0x77b0b658 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0 #7 0x77b09bc7 in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0 #8 0x77b0b658 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0 #9 0x77b09bc7 in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0 #10 0x77b0b658 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0 #11 0x77b09bc7 in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0 #12 0x77b0b658 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0 #13 0x77b09bc7 in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0 #14 0x77b0b658 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0 #15 0x77b0b762 in PyEval_EvalCode () from /usr/lib64/libpython2.7.so.1.0 #16 0x77b2545c in ?? () from /usr/lib64/libpython2.7.so.1.0 #17 0x77b25530 in PyRun_FileExFlags () from /usr/lib64/libpython2.7.so.1.0 #18 0x77b26a1f in PyRun_SimpleFileExFlags () from /usr/lib64/libpython2.7.so.1.0 #19 0x77b377cc in Py_Main () from /usr/lib64/libpython2.7.so.1.0 #20 0x774d4bad in __libc_start_main () from /lib64/libc.so.6 #21 0x004008c9 in _start () I have python 2.7.1 and amd64 linux distributive (gentoo). I did not see this problem on x86 linux. Thanks. -- BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users