From jslavin at cfa.harvard.edu Fri Feb 2 15:39:27 2018 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Fri, 2 Feb 2018 15:39:27 -0500 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou Message-ID: Hi all, I'm just getting started with running hydro calculations on NASA's Pleiades cluster. To view the results one can use the Lou nodes (dedicated to data analysis). I installed anaconda so that I could use matplotlib, but so far I can't find a backend that works. Qt5Agg leads to an error from libpthread about the GLIBC version. Qt4 fails with "No module named PyQt4". Anyway, does anyone have a solution to this? Of course, I could ask this of the NAS folks, but I thought it was likely that someone on this list had dealt with this problem. Regards, Jon -- ________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin at cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerzy.karczmarczuk at unicaen.fr Fri Feb 2 16:23:18 2018 From: jerzy.karczmarczuk at unicaen.fr (Jerzy Karczmarczuk) Date: Fri, 2 Feb 2018 22:23:18 +0100 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou In-Reply-To: References: Message-ID: <10e2370c-451d-57a5-ab6d-dcdaa43a8a03@unicaen.fr> Le 02/02/2018 ? 21:39, Slavin, Jonathan a ?crit?: > Qt5Agg leads to an error from libpthread about the GLIBC version.? Qt4 > fails with "No module named PyQt4".? Anyway, does anyone have a > solution to this? > > Of course, I could ask this of the NAS folks, but I thought it was > likely that someone on this list had dealt with this problem. Since you are a professional in astro-whatever, I *might* susepct that you loaded in your computer a good deal of specific software. I did that once, when I taught something the local folks name "informatique g?ographique".? Not knowing what I would really use, I fed the beast with at least 5 different GIS, and some other stuff, some of which came with their private copies of QT and PyQT. And there were conflicts... A thorough cleaning, elimination of double packages, isolating the environments, and ensuring that when I use Anaconda Matplotlib packages, its support is searched for first, really helped, not only me and my students, but some friends (local physicists) as well. No guarantee, though... Best regards Jerzy Karczmarczuk -------------- next part -------------- An HTML attachment was scrubbed... URL: From rory.yorke at gmail.com Sat Feb 3 00:00:29 2018 From: rory.yorke at gmail.com (Rory Yorke) Date: Sat, 03 Feb 2018 07:00:29 +0200 Subject: [Matplotlib-users] Replacing deprecated use of pyplot.subplot In-Reply-To: References: <87shb0mi25.fsf@gmail.com> Message-ID: <87h8qyu0pe.fsf@gmail.com> Hi Paul, Paul Hobson writes: >> In general, especially for library code, you should avoid relying on the >> pyplot state machine. OK, thanks. Eric said much the same in his reply. Thanks for the example code, that helps. It seems like the recommended overall approach is "if axes are provided, used them, else create new ones; return the axes used". For now we'll use the approach I've implemented, perhaps with Eric's suggested improvement. I'll propose creating a new suite of plot functions (there are several specialized plots we do: Bode, Nichols, etc.) that adopt the no-state-machine approach. Thanks, both to you and Eric. Regards, Rory From jslavin at cfa.harvard.edu Sun Feb 4 09:16:52 2018 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Sun, 4 Feb 2018 09:16:52 -0500 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou Message-ID: ?Jerzy, It's physics - astrophysics. In any case, since it's a NASA system I cannot load it up with a lot of software, though I did install the anaconda distribution as I mentioned. The issue is that the anaconda system does not include the toolkits needed to use the backends that display plots in a separate window. These include pygtk, PyQt5, wxpython, etc. and need to be installed for plotting via pyplot.show(). I could still use a jupyter notebook? ?though for me that's less desirable. Jon ? > > Date: Fri, 2 Feb 2018 22:23:18 +0100 > From: Jerzy Karczmarczuk > To: matplotlib-users at python.org > Subject: Re: [Matplotlib-users] backend for matplotlib on NAS Lou > Message-ID: <10e2370c-451d-57a5-ab6d-dcdaa43a8a03 at unicaen.fr> > Content-Type: text/plain; charset="utf-8"; Format="flowed" > > Le 02/02/2018 ? 21:39, Slavin, Jonathan a ?crit?: > > > Qt5Agg leads to an error from libpthread about the GLIBC version.? Qt4 > > fails with "No module named PyQt4".? Anyway, does anyone have a > > solution to this? > > > > Of course, I could ask this of the NAS folks, but I thought it was > > likely that someone on this list had dealt with this problem. > > Since you are a professional in astro-whatever, I *might* susepct that > you loaded in your computer a good deal of specific software. > I did that once, when I taught something the local folks name > "informatique g?ographique".? Not knowing what I would really use, I fed > the beast with at least 5 different GIS, and some other stuff, some of > which came with their private copies of QT and PyQT. And there were > conflicts... > A thorough cleaning, elimination of double packages, isolating the > environments, and ensuring that when I use Anaconda Matplotlib packages, > its support is searched for first, really helped, not only me and my > students, but some friends (local physicists) as well. No guarantee, > though... > > Best regards > > Jerzy Karczmarczuk > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: attachments/20180202/86375964/attachment-0001.html> > > ------------------------------ > > Message: 3 > Date: Sat, 03 Feb 2018 07:00:29 +0200 > From: Rory Yorke > To: matplotlib-users > Subject: Re: [Matplotlib-users] Replacing deprecated use of > pyplot.subplot > Message-ID: <87h8qyu0pe.fsf at gmail.com> > Content-Type: text/plain > > Hi Paul, > > Paul Hobson writes: > >> In general, especially for library code, you should avoid relying on the > >> pyplot state machine. > > OK, thanks. Eric said much the same in his reply. > > Thanks for the example code, that helps. It seems like the recommended > overall approach is "if axes are provided, used them, else create new ones; > return the axes used". > > For now we'll use the approach I've implemented, perhaps with Eric's > suggested improvement. I'll propose creating a new suite of plot > functions (there are several specialized plots we do: Bode, Nichols, > etc.) that adopt the no-state-machine approach. > > Thanks, both to you and Eric. > > Regards, > > Rory > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > > > ------------------------------ > > End of Matplotlib-users Digest, Vol 31, Issue 1 > *********************************************** > -- ________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin at cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerzy.karczmarczuk at unicaen.fr Sun Feb 4 10:12:20 2018 From: jerzy.karczmarczuk at unicaen.fr (Jerzy Karczmarczuk) Date: Sun, 4 Feb 2018 16:12:20 +0100 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou In-Reply-To: References: Message-ID: Jonathan Slavin explains : > since it's a NASA system I cannot load it up with a lot of software, > though I did install the anaconda distribution as I mentioned. The > issue is that the anaconda system does not include the toolkits needed > to use the backends that display plots in a separate window.? These > include pygtk, PyQt5, wxpython, etc. and need to be installed for > plotting via pyplot.show() Please, tell what is your platform, under which system. Which Python version. You seem not believing me that you may have conflicts between various QT instances. Perhaps...? Verify *all* the occurrences of your libraries susceptible of being used by the mpl backend variants. Use 'which', 'where', 'locate', etc., all that goes on your system. First of all, you must ensure and be certain that you launch what you think you do, and not some "parasites". BTW. I didn't use "show()" for a long time, plt.plot(...) plots, and that's it. All the best Jerzy From nathan12343 at gmail.com Sun Feb 4 10:22:29 2018 From: nathan12343 at gmail.com (Nathan Goldbaum) Date: Sun, 04 Feb 2018 15:22:29 +0000 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou In-Reply-To: References: Message-ID: I would also unload all modules you have loaded, if Lou has a module system installed. In the past I?ve found that the module system used on HPC systems can defeat the rpath trickery that conda uses to associate an extension module with a python package. On Sun, Feb 4, 2018 at 9:12 AM Jerzy Karczmarczuk < jerzy.karczmarczuk at unicaen.fr> wrote: > Jonathan Slavin explains : > > > since it's a NASA system I cannot load it up with a lot of software, > > though I did install the anaconda distribution as I mentioned. The > > issue is that the anaconda system does not include the toolkits needed > > to use the backends that display plots in a separate window. These > > include pygtk, PyQt5, wxpython, etc. and need to be installed for > > plotting via pyplot.show() > Please, tell what is your platform, under which system. Which Python > version. > You seem not believing me that you may have conflicts between various QT > instances. Perhaps... Verify *all* the occurrences of your libraries > susceptible of being used by the mpl backend variants. Use 'which', > 'where', 'locate', etc., all that goes on your system. > First of all, you must ensure and be certain that you launch what you > think you do, and not some "parasites". > BTW. I didn't use "show()" for a long time, plt.plot(...) plots, and > that's it. > > All the best > > Jerzy > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ccrook at linz.govt.nz Sun Feb 4 15:55:04 2018 From: ccrook at linz.govt.nz (Chris Crook) Date: Sun, 4 Feb 2018 20:55:04 +0000 Subject: [Matplotlib-users] tricontour crashing in QGIS3 Message-ID: I'm looking for help debugging or fixing a problem in matplotlib tricontour. I am using this in a QGIS plugin (www.qgis.org). The call to tricontour causes QGIS to crash. Running python3 on ubuntu 16.04 (matplotlib 1.5.1) and 17.10 (matplotlib 2.0.0). Running in the debugger gives the following result Thread 1 "qgis.bin" received signal SIGSEGV, Segmentation fault. 0x00007fff4f7ca098 in qh_initstatistics () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #0 0x00007fff4f7ca098 in qh_initstatistics () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #1 0x00007fff4f7c6f82 in qh_initqhull_start () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #2 0x00007fff4f7d12bc in qh_new_qhull () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #3 0x00007fff4f7a3821 in ?? () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #4 0x00007fff5d977039 in PyCFunction_Call () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #5 0x00007fff5da831b5 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #6 0x00007fff5db13cac in ?? () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #7 0x00007fff5db13d83 in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #8 0x00007fff5d99bad8 in ?? () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 .... The python code is np.save('/home/chris/temp/data.x',x) np.save('/home/chris/temp/data.y',y) np.save('/home/chris/temp/data.z',z) np.save('/home/chris/temp/data.l',levels) print("Extend",repr(extend)) cs = plt.tricontour(x, y, z, levels, extend=extend) I've called matplotlib from a simple python script using the saved data (np.save) in a simply python script and it runs without problem, so the problem appears to arise running within the QGIS3 python environment. Can you suggest any reason why it might be different running from within QGIS and how I can work around/fix this! Thanks Chris Crook ________________________________ This message contains information, which may be in confidence and may be subject to legal privilege. If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message. LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ. Thank You. From ben.v.root at gmail.com Sun Feb 4 17:54:45 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Sun, 4 Feb 2018 17:54:45 -0500 Subject: [Matplotlib-users] tricontour crashing in QGIS3 In-Reply-To: References: Message-ID: Looks like a conflict for the qhull library, which matplotlib vendors and builds as a part of its packaging. How did qgis and matplotlib get installed? Perhaps they were built with conflicting flags, perhaps? Just a few ideas off of the top of my head. Ben Root On Sun, Feb 4, 2018 at 3:55 PM, Chris Crook wrote: > I'm looking for help debugging or fixing a problem in matplotlib > tricontour. I am using this in a QGIS plugin (www.qgis.org). The call > to tricontour causes QGIS to crash. Running python3 on ubuntu 16.04 > (matplotlib 1.5.1) and 17.10 (matplotlib 2.0.0). > > Running in the debugger gives the following result > > Thread 1 "qgis.bin" received signal SIGSEGV, Segmentation fault. > 0x00007fff4f7ca098 in qh_initstatistics () > from /usr/lib/python3/dist-packages/matplotlib/_qhull. > cpython-35m-x86_64-linux-gnu.so > #0 0x00007fff4f7ca098 in qh_initstatistics () > from /usr/lib/python3/dist-packages/matplotlib/_qhull. > cpython-35m-x86_64-linux-gnu.so > #1 0x00007fff4f7c6f82 in qh_initqhull_start () > from /usr/lib/python3/dist-packages/matplotlib/_qhull. > cpython-35m-x86_64-linux-gnu.so > #2 0x00007fff4f7d12bc in qh_new_qhull () > from /usr/lib/python3/dist-packages/matplotlib/_qhull. > cpython-35m-x86_64-linux-gnu.so > #3 0x00007fff4f7a3821 in ?? () > from /usr/lib/python3/dist-packages/matplotlib/_qhull. > cpython-35m-x86_64-linux-gnu.so > #4 0x00007fff5d977039 in PyCFunction_Call () > from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 > #5 0x00007fff5da831b5 in PyEval_EvalFrameEx () > from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 > #6 0x00007fff5db13cac in ?? () > from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 > #7 0x00007fff5db13d83 in PyEval_EvalCodeEx () > from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 > #8 0x00007fff5d99bad8 in ?? () > from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 > .... > > The python code is > > np.save('/home/chris/temp/data.x',x) > np.save('/home/chris/temp/data.y',y) > np.save('/home/chris/temp/data.z',z) > np.save('/home/chris/temp/data.l',levels) > print("Extend",repr(extend)) > cs = plt.tricontour(x, y, z, levels, extend=extend) > > I've called matplotlib from a simple python script using the saved data > (np.save) in a simply python script and it runs without problem, so the > problem appears to arise running within the QGIS3 python environment. > > Can you suggest any reason why it might be different running from within > QGIS and how I can work around/fix this! > > Thanks > Chris Crook > > ________________________________ > > This message contains information, which may be in confidence and may be > subject to legal privilege. If you are not the intended recipient, you must > not peruse, use, disseminate, distribute or copy this message. If you have > received this message in error, please notify us immediately (Phone 0800 > 665 463 or info at linz.govt.nz) and destroy the original message. LINZ > accepts no responsibility for changes to this email, or for any > attachments, after its transmission from LINZ. Thank You. > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ccrook at linz.govt.nz Mon Feb 5 02:28:50 2018 From: ccrook at linz.govt.nz (Chris Crook) Date: Mon, 5 Feb 2018 07:28:50 +0000 Subject: [Matplotlib-users] tricontour crashing in QGIS3 In-Reply-To: References: , Message-ID: Thanks Benhamin. - I'll certainly look in to that. The installations are all using apt on ubuntu. Using standard repositories apart from the QGIS nightly build. I'm not sure if QGIS uses qhull directly or indirectly - I'll investigate that. ________________________________________ From: Benjamin Root [ben.v.root at gmail.com] Sent: 05 February 2018 11:55 To: Chris Crook Cc: matplotlib-users at python.org; qgis-developer at lists.osgeo.org Subject: Re: [Matplotlib-users] tricontour crashing in QGIS3 Looks like a conflict for the qhull library, which matplotlib vendors and builds as a part of its packaging. How did qgis and matplotlib get installed? Perhaps they were built with conflicting flags, perhaps? Just a few ideas off of the top of my head. Ben Root On Sun, Feb 4, 2018 at 3:55 PM, Chris Crook > wrote: I'm looking for help debugging or fixing a problem in matplotlib tricontour. I am using this in a QGIS plugin (www.qgis.org). The call to tricontour causes QGIS to crash. Running python3 on ubuntu 16.04 (matplotlib 1.5.1) and 17.10 (matplotlib 2.0.0). Running in the debugger gives the following result Thread 1 "qgis.bin" received signal SIGSEGV, Segmentation fault. 0x00007fff4f7ca098 in qh_initstatistics () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #0 0x00007fff4f7ca098 in qh_initstatistics () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #1 0x00007fff4f7c6f82 in qh_initqhull_start () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #2 0x00007fff4f7d12bc in qh_new_qhull () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #3 0x00007fff4f7a3821 in ?? () from /usr/lib/python3/dist-packages/matplotlib/_qhull.cpython-35m-x86_64-linux-gnu.so #4 0x00007fff5d977039 in PyCFunction_Call () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #5 0x00007fff5da831b5 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #6 0x00007fff5db13cac in ?? () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #7 0x00007fff5db13d83 in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 #8 0x00007fff5d99bad8 in ?? () from /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 .... The python code is np.save('/home/chris/temp/data.x',x) np.save('/home/chris/temp/data.y',y) np.save('/home/chris/temp/data.z',z) np.save('/home/chris/temp/data.l',levels) print("Extend",repr(extend)) cs = plt.tricontour(x, y, z, levels, extend=extend) I've called matplotlib from a simple python script using the saved data (np.save) in a simply python script and it runs without problem, so the problem appears to arise running within the QGIS3 python environment. Can you suggest any reason why it might be different running from within QGIS and how I can work around/fix this! Thanks Chris Crook ________________________________ This message contains information, which may be in confidence and may be subject to legal privilege. If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message. LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ. Thank You. _______________________________________________ Matplotlib-users mailing list Matplotlib-users at python.org https://mail.python.org/mailman/listinfo/matplotlib-users From kitecamguy at gmail.com Mon Feb 5 10:57:16 2018 From: kitecamguy at gmail.com (Glenn Nelson) Date: Mon, 5 Feb 2018 07:57:16 -0800 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou In-Reply-To: References: Message-ID: On my desktop I installed Anaconda last fall - so it's pretty recent. I also needed PyQt4. If that would solve your problem, here's one answer: https://stackoverflow.com/questions/21637922/how-to-install-pyqt4-in-anaconda Read thru and you will find "conda install pyqt=4". ---- Glenn Nelson in Santa Cruz social: http://google.com/+GlennNelson see my Kite Aerial Photos at http://www.glenn-nelson.us/kap On Fri, Feb 2, 2018 at 12:39 PM, Slavin, Jonathan wrote: > Hi all, > > I'm just getting started with running hydro calculations on NASA's > Pleiades cluster. To view the results one can use the Lou nodes (dedicated > to data analysis). I installed anaconda so that I could use matplotlib, > but so far I can't find a backend that works. Qt5Agg leads to an error > from libpthread about the GLIBC version. Qt4 fails with "No module named > PyQt4". Anyway, does anyone have a solution to this? > > Of course, I could ask this of the NAS folks, but I thought it was likely > that someone on this list had dealt with this problem. > > Regards, > Jon > > -- > ________________________________________________________ > Jonathan D. Slavin Harvard-Smithsonian CfA > jslavin at cfa.harvard.edu 60 Garden Street, MS 83 > phone: (617) 496-7981 Cambridge, MA 02138-1516 > cell: (781) 363-0035 USA > ________________________________________________________ > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jslavin at cfa.harvard.edu Mon Feb 5 11:19:30 2018 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Mon, 5 Feb 2018 11:19:30 -0500 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou Message-ID: The platform is Suse Linux Enterprise Server 12. Also, I checked and there are no modules loaded: > module list No Modulefiles Currently Loaded. I also checked that I was launching the anaconda version of python/ipython. ?To be more explicit about the error, if I use in my matplotlibrc: ?backend : Qt5Agg backend.qt4 : PyQt4 Then when I start up ipython with the --pylab argument, I get: [TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed? --------------------------------------------------------------------------- ImportError Traceback (most recent call last) /u/jdslavin/anaconda2/lib/python2.7/site-packages/IPython/core/shellapp.pyc in (key) 196 shell = self.shell 197 if self.pylab: --> 198 enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all) 199 key = self.pylab 200 elif self.matplotlib: ... (snipped) /u/jdslavin/anaconda2/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py in () 135 if QT_API == QT_API_PYQT5: 136 try: --> 137 from PyQt5 import QtCore, QtGui, QtWidgets 138 _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName 139 except ImportError: ImportError: /lib64/libpthread.so.0: version `GLIBC_2.12' not found (required by /u/jdslavin/anaconda2/lib/python2.7/site-packages/PyQt5/../../.././libglib-2.0.so.0) So I'm guessing that this has to do with the version of glibc installed rather than the missing gui toolkits as I had previously thought. It could be that loading some module might fix the problem, though I'm not sure if that's true or which one I'd need to load. Any ideas? Jon On Sun, Feb 4, 2018 at 10:28 AM, wrote: > > Date: Sun, 4 Feb 2018 16:12:20 +0100 > From: Jerzy Karczmarczuk > To: matplotlib-users at python.org > Subject: Re: [Matplotlib-users] backend for matplotlib on NAS Lou > Message-ID: > Content-Type: text/plain; charset=utf-8; format=flowed > > > Please, tell what is your platform, under which system. Which Python > version. > You seem not believing me that you may have conflicts between various QT > instances. Perhaps...? Verify *all* the occurrences of your libraries > susceptible of being used by the mpl backend variants. Use 'which', > 'where', 'locate', etc., all that goes on your system. > First of all, you must ensure and be certain that you launch what you > think you do, and not some "parasites". > BTW. I didn't use "show()" for a long time, plt.plot(...) plots, and > that's it. > > All the best > > Jerzy > > ------------------------------ > > Message: 3 > Date: Sun, 04 Feb 2018 15:22:29 +0000 > From: Nathan Goldbaum > To: Jerzy Karczmarczuk > Cc: matplotlib-users at python.org > Subject: Re: [Matplotlib-users] backend for matplotlib on NAS Lou > Message-ID: > gmail.com> > Content-Type: text/plain; charset="utf-8" > > I would also unload all modules you have loaded, if Lou has a module system > installed. In the past I?ve found that the module system used on HPC > systems can defeat the rpath trickery that conda uses to associate an > extension module with a python package. > -- ________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin at cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From tcaswell at gmail.com Mon Feb 5 21:44:38 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Tue, 06 Feb 2018 02:44:38 +0000 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou In-Reply-To: References: Message-ID: This should go either to anaconda support or to your local sysadmins. It may also be worth trying to us `tkagg` which tends to bundled with python and may have a higher chance of working. Tom On Mon, Feb 5, 2018 at 11:19 AM Slavin, Jonathan wrote: > The platform is Suse Linux Enterprise Server 12. > Also, I checked and there are no modules loaded: > > module list > No Modulefiles Currently Loaded. > > I also checked that I was launching the anaconda version of python/ipython. > > ?To be more explicit about the error, if I use in my matplotlibrc: > ?backend : Qt5Agg > backend.qt4 : PyQt4 > > Then when I start up ipython with the --pylab argument, I get: > [TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. > Is matplotlib installed? > --------------------------------------------------------------------------- > ImportError Traceback (most recent call last) > /u/jdslavin/anaconda2/lib/python2.7/site-packages/IPython/core/shellapp.pyc > in (key) > 196 shell = self.shell > 197 if self.pylab: > --> 198 enable = lambda key: shell.enable_pylab(key, > import_all=self.pylab_import_all) > 199 key = self.pylab > 200 elif self.matplotlib: > ... > (snipped) > > /u/jdslavin/anaconda2/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py > in () > 135 if QT_API == QT_API_PYQT5: > 136 try: > --> 137 from PyQt5 import QtCore, QtGui, QtWidgets > 138 _getSaveFileName = > QtWidgets.QFileDialog.getSaveFileName > 139 except ImportError: > > ImportError: /lib64/libpthread.so.0: version `GLIBC_2.12' not found > (required by > /u/jdslavin/anaconda2/lib/python2.7/site-packages/PyQt5/../../.././libglib-2.0.so.0) > > So I'm guessing that this has to do with the version of glibc installed > rather than the missing gui toolkits as I had previously thought. It could > be that loading some module might fix the problem, though I'm not sure if > that's true or which one I'd need to load. > Any ideas? > > Jon > > On Sun, Feb 4, 2018 at 10:28 AM, > wrote: >> >> Date: Sun, 4 Feb 2018 16:12:20 +0100 > > >> From: Jerzy Karczmarczuk >> To: matplotlib-users at python.org >> Subject: Re: [Matplotlib-users] backend for matplotlib on NAS Lou >> > Message-ID: >> Content-Type: text/plain; charset=utf-8; format=flowed > > >> >> >> Please, tell what is your platform, under which system. Which Python >> version. >> You seem not believing me that you may have conflicts between various QT >> > instances. Perhaps...? Verify *all* the occurrences of your libraries > > >> susceptible of being used by the mpl backend variants. Use 'which', >> 'where', 'locate', etc., all that goes on your system. >> First of all, you must ensure and be certain that you launch what you >> think you do, and not some "parasites". >> BTW. I didn't use "show()" for a long time, plt.plot(...) plots, and >> that's it. >> >> All the best >> >> Jerzy >> >> ------------------------------ >> >> Message: 3 >> Date: Sun, 04 Feb 2018 15:22:29 +0000 >> From: Nathan Goldbaum >> To: Jerzy Karczmarczuk >> Cc: matplotlib-users at python.org > > >> Subject: Re: [Matplotlib-users] backend for matplotlib on NAS Lou >> Message-ID: >> > > 91T3ewYo+SA at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" > > >> >> I would also unload all modules you have loaded, if Lou has a module >> system >> > installed. In the past I?ve found that the module system used on HPC > > >> systems can defeat the rpath trickery that conda uses to associate an >> extension module with a python package. >> > -- > ________________________________________________________ > Jonathan D. Slavin Harvard-Smithsonian CfA > jslavin at cfa.harvard.edu 60 Garden Street, MS 83 > phone: (617) 496-7981 Cambridge, MA 02138-1516 > cell: (781) 363-0035 USA > ________________________________________________________ > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jslavin at cfa.harvard.edu Thu Feb 8 09:38:59 2018 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Thu, 8 Feb 2018 09:38:59 -0500 Subject: [Matplotlib-users] backend for matplotlib on NAS Lou (Thomas Caswell) Message-ID: Just thought I report that I did get matplotlib working as desired on Lou. It turns out that using the version of matplotlib and ipython that's loaded by pkgsrc works (i.e. module load pkgsrc), if you set the backend to Qt4Agg or GtkAgg in your matplotlibrc. In my case I had to remove from my path the anaconda distribution that I had installed. I was also able to install yt using pip (with the --user argument so it installs under ~/.local). Regards, Jon On Tue, Feb 6, 2018 at 12:00 PM, wrote: > > Date: Tue, 06 Feb 2018 02:44:38 +0000 > From: Thomas Caswell > To: "Slavin, Jonathan" > Cc: Matplotlib-users > Subject: Re: [Matplotlib-users] backend for matplotlib on NAS Lou > Message-ID: > mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > This should go either to anaconda support or to your local sysadmins. > > It may also be worth trying to us `tkagg` which tends to bundled with > python and may have a higher chance of working. > > Tom > > On Mon, Feb 5, 2018 at 11:19 AM Slavin, Jonathan > wrote: > > > The platform is Suse Linux Enterprise Server 12. > > Also, I checked and there are no modules loaded: > > > module list > > No Modulefiles Currently Loaded. > > > > I also checked that I was launching the anaconda version of > python/ipython. > > > > ?To be more explicit about the error, if I use in my matplotlibrc: > > ?backend : Qt5Agg > > backend.qt4 : PyQt4 > > > > Then when I start up ipython with the --pylab argument, I get: > > [TerminalIPythonApp] WARNING | Eventloop or matplotlib integration > failed. > > Is matplotlib installed? > > ------------------------------------------------------------ > --------------- > > ImportError Traceback (most recent call > last) > > /u/jdslavin/anaconda2/lib/python2.7/site-packages/ > IPython/core/shellapp.pyc > > in (key) > > 196 shell = self.shell > > 197 if self.pylab: > > --> 198 enable = lambda key: shell.enable_pylab(key, > > import_all=self.pylab_import_all) > > 199 key = self.pylab > > 200 elif self.matplotlib: > > ... > > (snipped) > > > > /u/jdslavin/anaconda2/lib/python2.7/site-packages/ > matplotlib/backends/qt_compat.py > > in () > > 135 if QT_API == QT_API_PYQT5: > > 136 try: > > --> 137 from PyQt5 import QtCore, QtGui, QtWidgets > > 138 _getSaveFileName = > > QtWidgets.QFileDialog.getSaveFileName > > 139 except ImportError: > > > > ImportError: /lib64/libpthread.so.0: version `GLIBC_2.12' not found > > (required by > > /u/jdslavin/anaconda2/lib/python2.7/site-packages/PyQt5/ > ../../.././libglib-2.0.so.0) > > > > So I'm guessing that this has to do with the version of glibc installed > > rather than the missing gui toolkits as I had previously thought. It > could > > be that loading some module might fix the problem, though I'm not sure if > > that's true or which one I'd need to load. > > Any ideas? > > > > Jon > -- ________________________________________________________ Jonathan D. Slavin Harvard-Smithsonian CfA jslavin at cfa.harvard.edu 60 Garden Street, MS 83 phone: (617) 496-7981 Cambridge, MA 02138-1516 cell: (781) 363-0035 USA ________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pi at berkeley.edu Thu Feb 8 17:47:19 2018 From: pi at berkeley.edu (Paul Ivanov) Date: Thu, 8 Feb 2018 14:47:19 -0800 Subject: [Matplotlib-users] SciPy 2018 - one week left for submissions Message-ID: SciPy 2018, the 17th annual Scientific Computing with Python conference, will be held July 9-15, 2018 in Austin, Texas. The annual SciPyConference brings together over 700 participants from industry, academia, and government to showcase their latest projects, learn from skilled users and developers, and collaborate on code development. The call for abstracts for SciPy 2018 for talks, posters and tutorials is now open. The new extended deadline for submissions is February 15, 2018. Conference Website: https://scipy2018.scipy.org Submission Website: https://easychair.org/conferences/?conf=scipy2018 *July 9-15, 2018 | Austin, Texas * - *Tutorials:* July 9-10, 2018 - *Conference (Talks and Posters):* July 11-13, 2018 - *Sprints: *July 14-15, 2018 In addition to the general track, this year will have specialized tracks focused on: - Data Visualization - Reproducibility and Software Sustainability *Mini Symposia* ? Astronomy ? Biology and Bioinformatics ? Data Science ? Earth, Ocean and Geo Science ? Image Processing ? Language Interoperability ? Library Science and Digital Humanities ? Machine Learning ? Materials Science ? Political and Social Sciences There will also be a SciPy Tools Plenary Session each day with 2 to 5 minute updates on tools and libraries. *Tutorials (July 9-10, 2018)* Tutorials should be focused on covering a well-defined topic in a hands-on manner. We are looking for awesome techniques or packages, helping new or advanced Python programmers develop better or faster scientific applications. We encourage submissions to be designed to allow at least 50% of the time for hands-on exercises even if this means the subject matter needs to be limited. Tutorials will be 4 hours in duration. In your tutorial application, you can indicate what prerequisite skills and knowledge will be needed for your tutorial, and the approximate expected level of knowledge of your students (i.e., beginner, intermediate, advanced). Instructors of accepted tutorials will receive a stipend. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tcaswell at gmail.com Wed Feb 14 14:23:32 2018 From: tcaswell at gmail.com (Thomas Caswell) Date: Wed, 14 Feb 2018 19:23:32 +0000 Subject: [Matplotlib-users] [ANN] Matplotlib v2.2.0rc1 Message-ID: Folks, We are happy to release Matplotlib v2.2.0rc1! This is a feature release which includes new functionality (along with many bug-fixes). One of the hi-lights of this release is a constrained layout manager, please see https://matplotlib.org/devdocs/users/whats_new.html for details. API changes are at https://matplotlib.org/devdocs/api/api_changes.html The rc can be installed via pip pip install --pre matplotlib or via conda from conda-forge conda install -c conda-forge/label/rc matplotlib -c conda-forge The goal is to do 2.2.0 final around Mar. 2, please test these out and report bugs this week and next! mpl2.2 will be the last feature release in the Matplotlib 2.x series and the last feature release of Matplotlib to support python 2.7 and intend to provide bug fixes to 2.2 until 2020. We are looking for someone to take the lead on maintaining the 2.2.x branch, if you are interested please reach out! The next feature release after 2.2 will be 3.0 scheduled for July-August 2018. Thank you everyone (100+) who contributed to this release! Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From nunzio.losacco at uniroma2.it Wed Feb 14 18:58:01 2018 From: nunzio.losacco at uniroma2.it (Nunzio Losacco) Date: Thu, 15 Feb 2018 00:58:01 +0100 Subject: [Matplotlib-users] Add multiplier to logscale colorer Message-ID: <6567A5F5-40F4-4CD6-9326-22743413D5D6@uniroma2.it> Hi all, I am producing a contour plot with a lognormalized colorbar. If the levels are set to numpy.logspace(expmin,expmax,num) * mul the colorbar labels disappear. I would like them to be ?mul x 10^exp ? I have been playing a lot with formatters but I didn?t manage to obtain what I want. Any help? N ***************************************************************** Dr. Nunzio Losacco (PhD, MEng, MSc, DIC) PostDoctoral Fellow University of Rome "Tor Vergata" Department of Civil Engineering and Computer Science Via del Politecnico, 1 - 00133 - Roma Italy +39 0672597062 ***************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From kotaro.saito at psi.ch Thu Feb 15 05:08:06 2018 From: kotaro.saito at psi.ch (Saito Kotaro (PSI)) Date: Thu, 15 Feb 2018 11:08:06 +0100 Subject: [Matplotlib-users] Add multiplier to logscale colorer In-Reply-To: <6567A5F5-40F4-4CD6-9326-22743413D5D6@uniroma2.it> References: <6567A5F5-40F4-4CD6-9326-22743413D5D6@uniroma2.it> Message-ID: <17C37757-9EE3-4FCF-AF0F-17469BABA93A@psi.ch> Hi Nunzio, Colorbar in matplotlib is a bit tricky. Solutions for your problem might be different depending on whether you are using fig.colorbar or colorbar in ImageGrid. Can you show me a minimal working example? //================//================// Paul Scherrer Institut Kotaro SAITO ????? Laboratory for Neutron Scattering and Imaging WHGA/348 5232 Villigen PSI, Schweiz +41 56 310 3179 kotaro.saito at psi.ch https://sites.google.com/view/kotarosaito/ //================//================// > On 2018/2/ 15, at 00:58, Nunzio Losacco wrote: > > Hi all, > > I am producing a contour plot with a lognormalized colorbar. > If the levels are set to numpy.logspace(expmin,expmax,num) * mul > the colorbar labels disappear. > I would like them to be > > ?mul x 10^exp ? > > I have been playing a lot with formatters but I didn?t manage to obtain what I want. > > Any help? > > N > > ***************************************************************** > > Dr. Nunzio Losacco > (PhD, MEng, MSc, DIC) > PostDoctoral Fellow > University of Rome "Tor Vergata" > Department of Civil Engineering and Computer Science > Via del Politecnico, 1 - 00133 - Roma > Italy > > +39 0672597062 > > ***************************************************************** > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users From eric at depagne.org Fri Feb 16 04:36:40 2018 From: eric at depagne.org (=?ISO-8859-1?Q?=C9ric?= Depagne) Date: Fri, 16 Feb 2018 11:36:40 +0200 Subject: [Matplotlib-users] Efficiency in connecting two subplot. Message-ID: <2718503.CSJC07vTRv@portable> Hi all, I have a gridspec plot and one of the subplot is a zoom on the part over which the mouse hovers on another subplot. It works, but I think the way I implemented it is not very efficient, since each time I use it, I see one CPU go to 100%. Here is the code that does implement the zoom. Any idea on how to make it (more) efficient or changes that I should implement welcome. Thanks. def plot(self): gs = gridspec.GridSpec(6, 2) ax1 = plt.subplot(gs[1:, 0]) plt1 = ax1.imshow(self.data, vmin=self.dataminzs, vmax=self.datamaxzs) ax1.set_label('AX1') self.ax2 = plt.subplot(gs[0:3, 1]) zoomeddata = self.data[np.int(self.data.shape[0]/ 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/ 2)-50:np.int(self.data.shape[1]/2)+50] self.plt2 = self.ax2.imshow(zoomeddata, vmin=self.dataminzs, vmax=self.datamaxzs) ax1.figure.canvas.mpl_connect('motion_notify_event', self._on_move) def _on_move(self, event): zoom1 = 100 if event.inaxes: ax = event.inaxes # the axes instance if 'AX1' in ax.get_label(): # Mouse is in subplot 1. xinf2 = np.int(event.xdata - zoom1) xsup2 = np.int(event.xdata + zoom1) yinf2 = np.int(event.ydata - zoom1) ysup2 = np.int(event.ydata + zoom1) ax2data = self.data[yinf2:ysup2, xinf2:xsup2] self.plt2.set_data(ax2data) self.ax2.figure.canvas.draw() -- Un clavier azerty en vaut deux ---------------------------------------------------------- ?ric Depagne From vincent.adrien at gmail.com Fri Feb 16 14:41:07 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Fri, 16 Feb 2018 11:41:07 -0800 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: <2718503.CSJC07vTRv@portable> References: <2718503.CSJC07vTRv@portable> Message-ID: Hi ?ric, I am not very used to play with interactive events, but I guess some blitting could help you with performance: - https://stackoverflow.com/questions/29277080/efficient-matplotlib-redrawing - https://matplotlib.org/users/event_handling.html#draggable-rectangle-exercise (see the extra credit example) See the attached script that is inspired from your code and seems to less stress my CPU. Hopefully this helps. Best, Adrien On 02/16/2018 01:36 AM, ?ric Depagne wrote: > Hi all, > > I have a gridspec plot and one of the subplot is a zoom on the part over which > the mouse hovers on another subplot. > > It works, but I think the way I implemented it is not very efficient, since each > time I use it, I see one CPU go to 100%. > Here is the code that does implement the zoom. Any idea on how to make it > (more) efficient or changes that I should implement welcome. > > Thanks. > > def plot(self): > gs = gridspec.GridSpec(6, 2) > ax1 = plt.subplot(gs[1:, 0]) > plt1 = ax1.imshow(self.data, vmin=self.dataminzs, vmax=self.datamaxzs) > ax1.set_label('AX1') > self.ax2 = plt.subplot(gs[0:3, 1]) > zoomeddata = self.data[np.int(self.data.shape[0]/ > 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/ > 2)-50:np.int(self.data.shape[1]/2)+50] > self.plt2 = self.ax2.imshow(zoomeddata, vmin=self.dataminzs, > vmax=self.datamaxzs) > ax1.figure.canvas.mpl_connect('motion_notify_event', self._on_move) > > def _on_move(self, event): > zoom1 = 100 > if event.inaxes: > > ax = event.inaxes # the axes instance > if 'AX1' in ax.get_label(): > # Mouse is in subplot 1. > xinf2 = np.int(event.xdata - zoom1) > xsup2 = np.int(event.xdata + zoom1) > yinf2 = np.int(event.ydata - zoom1) > ysup2 = np.int(event.ydata + zoom1) > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > self.plt2.set_data(ax2data) > self.ax2.figure.canvas.draw() > -------------- next part -------------- A non-text attachment was scrubbed... Name: playground_blit.py Type: text/x-python Size: 2154 bytes Desc: not available URL: From teernabachoo at gmail.com Sun Feb 18 14:38:34 2018 From: teernabachoo at gmail.com (tia) Date: Sun, 18 Feb 2018 12:38:34 -0700 (MST) Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number Message-ID: <1518982714568-0.post@n5.nabble.com> I am trying to get sensor data from Ubidots and plot them in a graph using Matplotlib. The graph can then be displayed on a web server via Flask. I am getting the following error when I run the codes: TypeError: float() argument must be a string or a number I think I have formatted the timestamp well and I checked questions related to that but I don't know what's wrong with the codes. This may seem like a duplicate of my previous [question][1] but this is another error with updated codes so I thought I should post it as a new question. Matplotlib-Flask.py from flask import Flask, request, render_template from datetime import datetime from ubidots import ApiClient import matplotlib.pyplot as plt import matplotlib.dates as mdates import matplotlib.animation as animation from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import io app = Flask(__name__) //get the latest value of the ldr sensor from Ubidots def get_records(): api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXX') my_variable = api.get_variable('XXXXXXXXXXXXXXXXXXXX') ldr = my_variable.get_values(1) return ldr //get the latest timestamp from Ubidots def get_times(): api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXXX') variable = api.get_variable('XXXXXXXXXXXXXXXXXXXXXX') value = variable.get_values(1)[0] timestamp = value.get('timestamp') global t t= mdates.epoch2num(timestamp) return t //render the graph with x and y values of time and sensor values respectively and send to Flask @app.route('/', methods=['POST']) def my_form_post(): ldr= get_records() time= get_time() templateData = { 'ldr' : ldr, 'time' : t } return render_template('main.html', **templateData) //Plotting the graph using Matplotlib @app.route('/') def plot_temp(): ldr= get_records() ys = ldr fig = Figure() axis = fig.add_subplot(1,1,1) axis.set_title("Light Intensity") axis.set_xlabel("Time") axis.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S')) axis.grid(True) time= get_times() xs = time axis.plot(xs,ys) canvas = FigureCanvas(fig) output = io.BytesIO() canvas.print_png(output) response = make_response(output.getvalue()) response.mimetype = 'image/png' ani= animation.FuncAnimation(fig, animate, interval=3000) return response if __name__ == "__main__": app.run(host='0.0.0.0', port=80, debug=True) main.html: {{ title }} Hello, World! The date and time on the server is: {{ time }} I used the following reference links in case that helps: Ubidots timestamp: http://community.ubidots.com/t/convert-timestamp-on-json/473/2 Ubidots Python API: https://github.com/ubidots/ubidots-python Flask: http://www.mattrichardson.com/Raspberry-Pi-Flask/index.html Matplotlib graph using Flask: http://www.instructables.com/id/From-Data-to-Graph-a-Web-Jorney-With-Flask-and-SQL/ [1]: https://stackoverflow.com/questions/48849227/matplotlib-getting-valueerror-invalid-literal-for-float -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From teernabachoo at gmail.com Sun Feb 18 14:43:04 2018 From: teernabachoo at gmail.com (tia) Date: Sun, 18 Feb 2018 12:43:04 -0700 (MST) Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number Message-ID: <1518982984579-0.post@n5.nabble.com> I am trying to get sensor data from Ubidots and plot them in a graph using Matplotlib. The graph can then be displayed on a web server via Flask. I am getting the following error when I run the codes: TypeError: float() argument must be a string or a number Matplotlib-Flask.py from flask import Flask, request, render_template from datetime import datetime from ubidots import ApiClient import matplotlib.pyplot as plt import matplotlib.dates as mdates import matplotlib.animation as animation from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import io app = Flask(__name__) //get the latest value of the ldr sensor from Ubidots def get_records(): api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXX') my_variable = api.get_variable('XXXXXXXXXXXXXXXXXXXX') ldr = my_variable.get_values(1) return ldr //get the latest timestamp from Ubidots def get_times(): api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXXX') variable = api.get_variable('XXXXXXXXXXXXXXXXXXXXXX') value = variable.get_values(1)[0] timestamp = value.get('timestamp') global t t= mdates.epoch2num(timestamp) return t //render the graph with x and y values of time and sensor values respectively and send to Flask @app.route('/', methods=['POST']) def my_form_post(): ldr= get_records() time= get_time() templateData = { 'ldr' : ldr, 'time' : t } return render_template('main.html', **templateData) //Plotting the graph using Matplotlib @app.route('/') def plot_temp(): ldr= get_records() ys = ldr fig = Figure() axis = fig.add_subplot(1,1,1) axis.set_title("Light Intensity") axis.set_xlabel("Time") axis.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S')) axis.grid(True) time= get_times() xs = time axis.plot(xs,ys) canvas = FigureCanvas(fig) output = io.BytesIO() canvas.print_png(output) response = make_response(output.getvalue()) response.mimetype = 'image/png' ani= animation.FuncAnimation(fig, animate, interval=3000) return response if __name__ == "__main__": app.run(host='0.0.0.0', port=80, debug=True) I used the following reference links in case that helps: Ubidots timestamp: http://community.ubidots.com/t/convert-timestamp-on-json/473/2 Ubidots Python API: https://github.com/ubidots/ubidots-python Flask: http://www.mattrichardson.com/Raspberry-Pi-Flask/index.html Matplotlib graph using Flask: http://www.instructables.com/id/From-Data-to-Graph-a-Web-Jorney-With-Flask-and-SQL/ -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From jklymak at uvic.ca Sun Feb 18 18:50:10 2018 From: jklymak at uvic.ca (Jody Klymak) Date: Sun, 18 Feb 2018 16:50:10 -0700 Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number In-Reply-To: <1518982984579-0.post@n5.nabble.com> References: <1518982984579-0.post@n5.nabble.com> Message-ID: Hi, Can you whittle this down to a self-contained small example? Cheers, Jody > On Feb 18, 2018, at 12:43 PM, tia wrote: > > I am trying to get sensor data from Ubidots and plot them in a graph using > Matplotlib. The graph can then be displayed on a web server via Flask. I am > getting the following error when I run the codes: > > TypeError: float() argument must be a string or a number > > Matplotlib-Flask.py > > from flask import Flask, request, render_template > from datetime import datetime > from ubidots import ApiClient > import matplotlib.pyplot as plt > import matplotlib.dates as mdates > import matplotlib.animation as animation > from matplotlib.backends.backend_agg import FigureCanvasAgg as > FigureCanvas > from matplotlib.figure import Figure > import io > > app = Flask(__name__) > > //get the latest value of the ldr sensor from Ubidots > def get_records(): > api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXX') > my_variable = api.get_variable('XXXXXXXXXXXXXXXXXXXX') > ldr = my_variable.get_values(1) > return ldr > > //get the latest timestamp from Ubidots > def get_times(): > api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXXX') > variable = api.get_variable('XXXXXXXXXXXXXXXXXXXXXX') > value = variable.get_values(1)[0] > timestamp = value.get('timestamp') > global t > t= mdates.epoch2num(timestamp) > return t > > //render the graph with x and y values of time and sensor values > respectively and send to Flask > @app.route('/', methods=['POST']) > def my_form_post(): > ldr= get_records() > time= get_time() > templateData = { > 'ldr' : ldr, > 'time' : t > } > return render_template('main.html', **templateData) > > //Plotting the graph using Matplotlib > @app.route('/') > def plot_temp(): > ldr= get_records() > ys = ldr > fig = Figure() > axis = fig.add_subplot(1,1,1) > axis.set_title("Light Intensity") > axis.set_xlabel("Time") > axis.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S')) > axis.grid(True) > time= get_times() > xs = time > axis.plot(xs,ys) > canvas = FigureCanvas(fig) > output = io.BytesIO() > canvas.print_png(output) > response = make_response(output.getvalue()) > response.mimetype = 'image/png' > ani= animation.FuncAnimation(fig, animate, interval=3000) > return response > > if __name__ == "__main__": > app.run(host='0.0.0.0', port=80, debug=True) > > I used the following reference links in case that helps: > > Ubidots timestamp: > http://community.ubidots.com/t/convert-timestamp-on-json/473/2 > > Ubidots Python API: https://github.com/ubidots/ubidots-python > > Flask: http://www.mattrichardson.com/Raspberry-Pi-Flask/index.html > > Matplotlib graph using Flask: > http://www.instructables.com/id/From-Data-to-Graph-a-Web-Jorney-With-Flask-and-SQL/ > > > > > > -- > Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users From ben.v.root at gmail.com Sun Feb 18 20:10:04 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Sun, 18 Feb 2018 20:10:04 -0500 Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number In-Reply-To: References: <1518982984579-0.post@n5.nabble.com> Message-ID: it woulld also help to have the full traceback. On Sun, Feb 18, 2018 at 6:50 PM, Jody Klymak wrote: > Hi, > > Can you whittle this down to a self-contained small example? > > Cheers, Jody > > > > > On Feb 18, 2018, at 12:43 PM, tia wrote: > > > > I am trying to get sensor data from Ubidots and plot them in a graph > using > > Matplotlib. The graph can then be displayed on a web server via Flask. I > am > > getting the following error when I run the codes: > > > > TypeError: float() argument must be a string or a number > > > > Matplotlib-Flask.py > > > > from flask import Flask, request, render_template > > from datetime import datetime > > from ubidots import ApiClient > > import matplotlib.pyplot as plt > > import matplotlib.dates as mdates > > import matplotlib.animation as animation > > from matplotlib.backends.backend_agg import FigureCanvasAgg as > > FigureCanvas > > from matplotlib.figure import Figure > > import io > > > > app = Flask(__name__) > > > > //get the latest value of the ldr sensor from Ubidots > > def get_records(): > > api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXX') > > my_variable = api.get_variable('XXXXXXXXXXXXXXXXXXXX') > > ldr = my_variable.get_values(1) > > return ldr > > > > //get the latest timestamp from Ubidots > > def get_times(): > > api = ApiClient(token='XXXXXXXXXXXXXXXXXXXXXXXX') > > variable = api.get_variable('XXXXXXXXXXXXXXXXXXXXXX') > > value = variable.get_values(1)[0] > > timestamp = value.get('timestamp') > > global t > > t= mdates.epoch2num(timestamp) > > return t > > > > //render the graph with x and y values of time and sensor values > > respectively and send to Flask > > @app.route('/', methods=['POST']) > > def my_form_post(): > > ldr= get_records() > > time= get_time() > > templateData = { > > 'ldr' : ldr, > > 'time' : t > > } > > return render_template('main.html', **templateData) > > > > //Plotting the graph using Matplotlib > > @app.route('/') > > def plot_temp(): > > ldr= get_records() > > ys = ldr > > fig = Figure() > > axis = fig.add_subplot(1,1,1) > > axis.set_title("Light Intensity") > > axis.set_xlabel("Time") > > axis.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S')) > > axis.grid(True) > > time= get_times() > > xs = time > > axis.plot(xs,ys) > > canvas = FigureCanvas(fig) > > output = io.BytesIO() > > canvas.print_png(output) > > response = make_response(output.getvalue()) > > response.mimetype = 'image/png' > > ani= animation.FuncAnimation(fig, animate, interval=3000) > > return response > > > > if __name__ == "__main__": > > app.run(host='0.0.0.0', port=80, debug=True) > > > > I used the following reference links in case that helps: > > > > Ubidots timestamp: > > http://community.ubidots.com/t/convert-timestamp-on-json/473/2 > > > > Ubidots Python API: https://github.com/ubidots/ubidots-python > > > > Flask: http://www.mattrichardson.com/Raspberry-Pi-Flask/index.html > > > > Matplotlib graph using Flask: > > http://www.instructables.com/id/From-Data-to-Graph-a-Web- > Jorney-With-Flask-and-SQL/ > > > > > > > > > > > > -- > > Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users- > f3.html > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users at python.org > > https://mail.python.org/mailman/listinfo/matplotlib-users > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From teernabachoo at gmail.com Mon Feb 19 01:44:03 2018 From: teernabachoo at gmail.com (tia) Date: Sun, 18 Feb 2018 23:44:03 -0700 (MST) Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number In-Reply-To: References: <1518982984579-0.post@n5.nabble.com> Message-ID: <1519022643378-0.post@n5.nabble.com> def get_UbiTimestamp(): api = ApiClient(token='A1E-6l4DwwC86SDR6QRTJWXGDwshTGPHFl') variable = api.get_variable('5a5f80eec03f971388983b8e') value = variable.get_values(1)[0] timestamp = value.get('timestamp') t= mdate.epoch2num(raw) return t def plot_temp(): ldr= get_records() ys = ldr fig = Figure() axis = fig.add_subplot(1,1,1) axis.set_title("Light Intensity") axis.set_xlabel("Time") axis.xaxis.set_major_formatter(mdate.DateFormatter('%H:%M:%S')) axis.grid(True) time= get_UbiTimestamp() xs = time axis.plot(xs,ys) canvas = FigureCanvas(fig) output = io.BytesIO() canvas.print_png(output) response = make_response(output.getvalue()) response.mimetype = 'image/png' ani= animation.FuncAnimation(fig, animate, interval=3000) return response Apparently the timestamp format is giving the following errors: Complete traceback: File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1997, in __call__ return self.wsgi_app(environ, start_response) File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/pi/MatPlotLib-Flask.py", line 51, in plot_temp axis.plot(xs,ys) File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1894, in inner return func(ax, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 1407, in plot self.add_line(line) File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 1787, in add_line self._update_line_limits(line) File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 1809, in _update_line_limits path = line.get_path() File "/usr/lib/python2.7/dist-packages/matplotlib/lines.py", line 989, in get_path self.recache() File "/usr/lib/python2.7/dist-packages/matplotlib/lines.py", line 685, in recache y = np.asarray(yconv, np.float_) File "/usr/lib/python2.7/dist-packages/numpy/core/numeric.py", line 531, in asarray return array(a, dtype, copy=False, order=order) TypeError: float() argument must be a string or a number -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From teernabachoo at gmail.com Mon Feb 19 01:46:39 2018 From: teernabachoo at gmail.com (tia) Date: Sun, 18 Feb 2018 23:46:39 -0700 (MST) Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number In-Reply-To: <1519022643378-0.post@n5.nabble.com> References: <1518982984579-0.post@n5.nabble.com> <1519022643378-0.post@n5.nabble.com> Message-ID: <1519022799390-0.post@n5.nabble.com> I posted the full traceback in a reply to the above answer. Do check it please. -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From teernabachoo at gmail.com Mon Feb 19 02:06:16 2018 From: teernabachoo at gmail.com (tia) Date: Mon, 19 Feb 2018 00:06:16 -0700 (MST) Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number In-Reply-To: References: <1518982984579-0.post@n5.nabble.com> Message-ID: <1519023976762-0.post@n5.nabble.com> The error I believe is in the way the timestamp has been formatted. -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From teernabachoo at gmail.com Mon Feb 19 02:07:12 2018 From: teernabachoo at gmail.com (tia) Date: Mon, 19 Feb 2018 00:07:12 -0700 (MST) Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number In-Reply-To: References: <1518982984579-0.post@n5.nabble.com> Message-ID: <1519024032283-0.post@n5.nabble.com> The error I believe is in the way the timestamp has been formatted. -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html From ben.v.root at gmail.com Mon Feb 19 09:33:58 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Mon, 19 Feb 2018 09:33:58 -0500 Subject: [Matplotlib-users] TypeError: float() argument must be a string or a number In-Reply-To: <1519024032283-0.post@n5.nabble.com> References: <1518982984579-0.post@n5.nabble.com> <1519024032283-0.post@n5.nabble.com> Message-ID: This is incomplete: ``` def get_UbiTimestamp(): api = ApiClient(token='A1E-6l4DwwC86SDR6QRTJWXGDwshTGPHFl') variable = api.get_variable('5a5f80eec03f971388983b8e') value = variable.get_values(1)[0] timestamp = value.get('timestamp') t= mdate.epoch2num(raw) return t ``` `raw` is undefined. Also, nothing in that traceback indicates a problem with datetime formatting, so what makes you think that is the problem? On Mon, Feb 19, 2018 at 2:07 AM, tia wrote: > The error I believe is in the way the timestamp has been formatted. > > > > -- > Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users- > f3.html > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric at depagne.org Mon Feb 19 09:37:38 2018 From: eric at depagne.org (=?ISO-8859-1?Q?=C9ric?= Depagne) Date: Mon, 19 Feb 2018 16:37:38 +0200 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: References: <2718503.CSJC07vTRv@portable> Message-ID: <7872196.kKXBaVDImM@portable> Le vendredi 16 f?vrier 2018, 21:41:07 SAST vincent.adrien at gmail.com a ?crit : Hi Adrien, Thanks for the answer, I'll have a look and will try to get things working a bit more efficiently. Cheers, ?ric. > Hi ?ric, > > I am not very used to play with interactive events, but I guess some > blitting could help you with performance: > - > https://stackoverflow.com/questions/29277080/efficient-matplotlib-redrawing > - > https://matplotlib.org/users/event_handling.html#draggable-rectangle-exercis > e (see the extra credit example) > > See the attached script that is inspired from your code and seems to > less stress my CPU. > > Hopefully this helps. > > Best, > Adrien > > On 02/16/2018 01:36 AM, ?ric Depagne wrote: > > Hi all, > > > > I have a gridspec plot and one of the subplot is a zoom on the part over > > which the mouse hovers on another subplot. > > > > It works, but I think the way I implemented it is not very efficient, > > since each time I use it, I see one CPU go to 100%. > > Here is the code that does implement the zoom. Any idea on how to make it > > (more) efficient or changes that I should implement welcome. > > > > Thanks. > > > > def plot(self): > > gs = gridspec.GridSpec(6, 2) > > ax1 = plt.subplot(gs[1:, 0]) > > plt1 = ax1.imshow(self.data, vmin=self.dataminzs, > > vmax=self.datamaxzs) > > ax1.set_label('AX1') > > self.ax2 = plt.subplot(gs[0:3, 1]) > > zoomeddata = self.data[np.int(self.data.shape[0]/ > > > > 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/ > > 2)-50:np.int(self.data.shape[1]/2)+50] > > > > self.plt2 = self.ax2.imshow(zoomeddata, vmin=self.dataminzs, > > > > vmax=self.datamaxzs) > > > > ax1.figure.canvas.mpl_connect('motion_notify_event', > > self._on_move) > > > > def _on_move(self, event): > > zoom1 = 100 > > > > if event.inaxes: > > ax = event.inaxes # the axes instance > > > > if 'AX1' in ax.get_label(): > > # Mouse is in subplot 1. > > xinf2 = np.int(event.xdata - zoom1) > > xsup2 = np.int(event.xdata + zoom1) > > yinf2 = np.int(event.ydata - zoom1) > > ysup2 = np.int(event.ydata + zoom1) > > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > > self.plt2.set_data(ax2data) > > self.ax2.figure.canvas.draw() -- Un clavier azerty en vaut deux ---------------------------------------------------------- ?ric Depagne From ben.v.root at gmail.com Mon Feb 19 10:04:28 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Mon, 19 Feb 2018 10:04:28 -0500 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: <7872196.kKXBaVDImM@portable> References: <2718503.CSJC07vTRv@portable> <7872196.kKXBaVDImM@portable> Message-ID: You might want to consider not having the limits change at *every* mouse motion over the axes. You can add a function state variable and maybe have it refresh every other motion or so. ``` def _on_move(self, event): zoom1 = 100 if event.inaxes: ax = event.inaxes # the axes instance if 'AX1' in ax.get_label(): _on_move.counter += 1 if _on_move.counter % 2: return # Mouse is in subplot 1. xinf2 = np.int(event.xdata - zoom1) xsup2 = np.int(event.xdata + zoom1) yinf2 = np.int(event.ydata - zoom1) ysup2 = np.int(event.ydata + zoom1) ax2data = self.data[yinf2:ysup2, xinf2:xsup2] self.plt2.set_data(ax2data) self.ax2.figure.canvas.draw() _on_move.counter = 0 ``` Another approach could be done where you capture the timestamp of when this function was last used for updating the limits, and only do a new limit update if a certain amount of time passed, such as half a second or so. Cheers! Ben Root On Mon, Feb 19, 2018 at 9:37 AM, ?ric Depagne wrote: > Le vendredi 16 f?vrier 2018, 21:41:07 SAST vincent.adrien at gmail.com a > ?crit : > Hi Adrien, > > Thanks for the answer, I'll have a look and will try to get things working > a > bit more efficiently. > > Cheers, > ?ric. > > Hi ?ric, > > > > I am not very used to play with interactive events, but I guess some > > blitting could help you with performance: > > - > > https://stackoverflow.com/questions/29277080/efficient- > matplotlib-redrawing > > - > > https://matplotlib.org/users/event_handling.html#draggable- > rectangle-exercis > > e (see the extra credit example) > > > > See the attached script that is inspired from your code and seems to > > less stress my CPU. > > > > Hopefully this helps. > > > > Best, > > Adrien > > > > On 02/16/2018 01:36 AM, ?ric Depagne wrote: > > > Hi all, > > > > > > I have a gridspec plot and one of the subplot is a zoom on the part > over > > > which the mouse hovers on another subplot. > > > > > > It works, but I think the way I implemented it is not very efficient, > > > since each time I use it, I see one CPU go to 100%. > > > Here is the code that does implement the zoom. Any idea on how to make > it > > > (more) efficient or changes that I should implement welcome. > > > > > > Thanks. > > > > > > def plot(self): > > > gs = gridspec.GridSpec(6, 2) > > > ax1 = plt.subplot(gs[1:, 0]) > > > plt1 = ax1.imshow(self.data, vmin=self.dataminzs, > > > vmax=self.datamaxzs) > > > ax1.set_label('AX1') > > > self.ax2 = plt.subplot(gs[0:3, 1]) > > > zoomeddata = self.data[np.int(self.data.shape[0]/ > > > > > > 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/ > > > 2)-50:np.int(self.data.shape[1]/2)+50] > > > > > > self.plt2 = self.ax2.imshow(zoomeddata, vmin=self.dataminzs, > > > > > > vmax=self.datamaxzs) > > > > > > ax1.figure.canvas.mpl_connect('motion_notify_event', > > > self._on_move) > > > > > > def _on_move(self, event): > > > zoom1 = 100 > > > > > > if event.inaxes: > > > ax = event.inaxes # the axes instance > > > > > > if 'AX1' in ax.get_label(): > > > # Mouse is in subplot 1. > > > xinf2 = np.int(event.xdata - zoom1) > > > xsup2 = np.int(event.xdata + zoom1) > > > yinf2 = np.int(event.ydata - zoom1) > > > ysup2 = np.int(event.ydata + zoom1) > > > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > > > self.plt2.set_data(ax2data) > > > self.ax2.figure.canvas.draw() > > > -- > Un clavier azerty en vaut deux > ---------------------------------------------------------- > ?ric Depagne > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric at depagne.org Mon Feb 19 10:14:23 2018 From: eric at depagne.org (=?ISO-8859-1?Q?=C9ric?= Depagne) Date: Mon, 19 Feb 2018 17:14:23 +0200 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: References: <2718503.CSJC07vTRv@portable> Message-ID: <1790692.Fm4p72jkeF@portable> Le vendredi 16 f?vrier 2018, 21:41:07 SAST vincent.adrien at gmail.com a ?crit : Hi Adrien, Many thanks for your code, I've modified mine in order to take advantage of the blitting, and it works beautifully. ?ric. > Hi ?ric, > > I am not very used to play with interactive events, but I guess some > blitting could help you with performance: > - > https://stackoverflow.com/questions/29277080/efficient-matplotlib-redrawing > - > https://matplotlib.org/users/event_handling.html#draggable-rectangle-exercis > e (see the extra credit example) > > See the attached script that is inspired from your code and seems to > less stress my CPU. > > Hopefully this helps. > > Best, > Adrien > > On 02/16/2018 01:36 AM, ?ric Depagne wrote: > > Hi all, > > > > I have a gridspec plot and one of the subplot is a zoom on the part over > > which the mouse hovers on another subplot. > > > > It works, but I think the way I implemented it is not very efficient, > > since each time I use it, I see one CPU go to 100%. > > Here is the code that does implement the zoom. Any idea on how to make it > > (more) efficient or changes that I should implement welcome. > > > > Thanks. > > > > def plot(self): > > gs = gridspec.GridSpec(6, 2) > > ax1 = plt.subplot(gs[1:, 0]) > > plt1 = ax1.imshow(self.data, vmin=self.dataminzs, > > vmax=self.datamaxzs) > > ax1.set_label('AX1') > > self.ax2 = plt.subplot(gs[0:3, 1]) > > zoomeddata = self.data[np.int(self.data.shape[0]/ > > > > 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/ > > 2)-50:np.int(self.data.shape[1]/2)+50] > > > > self.plt2 = self.ax2.imshow(zoomeddata, vmin=self.dataminzs, > > > > vmax=self.datamaxzs) > > > > ax1.figure.canvas.mpl_connect('motion_notify_event', > > self._on_move) > > > > def _on_move(self, event): > > zoom1 = 100 > > > > if event.inaxes: > > ax = event.inaxes # the axes instance > > > > if 'AX1' in ax.get_label(): > > # Mouse is in subplot 1. > > xinf2 = np.int(event.xdata - zoom1) > > xsup2 = np.int(event.xdata + zoom1) > > yinf2 = np.int(event.ydata - zoom1) > > ysup2 = np.int(event.ydata + zoom1) > > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > > self.plt2.set_data(ax2data) > > self.ax2.figure.canvas.draw() -- Un clavier azerty en vaut deux ---------------------------------------------------------- ?ric Depagne From eric at depagne.org Tue Feb 20 02:57:06 2018 From: eric at depagne.org (=?ISO-8859-1?Q?=C9ric?= Depagne) Date: Tue, 20 Feb 2018 09:57:06 +0200 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: References: <2718503.CSJC07vTRv@portable> <7872196.kKXBaVDImM@portable> Message-ID: <1794988.hQncGMomWA@portable> Le lundi 19 f?vrier 2018, 17:04:28 SAST Benjamin Root a ?crit : Hi Ben, Thanks for the idea. I'll see how my code runs on a slower computer than mine, and I'll implement it should I find my current solution too slow. ?ric. > You might want to consider not having the limits change at *every* mouse > motion over the axes. You can add a function state variable and maybe have > it refresh every other motion or so. > > ``` > def _on_move(self, event): > zoom1 = 100 > if event.inaxes: > > ax = event.inaxes # the axes instance > if 'AX1' in ax.get_label(): > _on_move.counter += 1 > if _on_move.counter % 2: > return > # Mouse is in subplot 1. > xinf2 = np.int(event.xdata - zoom1) > xsup2 = np.int(event.xdata + zoom1) > yinf2 = np.int(event.ydata - zoom1) > ysup2 = np.int(event.ydata + zoom1) > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > self.plt2.set_data(ax2data) > self.ax2.figure.canvas.draw() > _on_move.counter = 0 > ``` > Another approach could be done where you capture the timestamp of when this > function was last used for updating the limits, and only do a new limit > update if a certain amount of time passed, such as half a second or so. > > Cheers! > Ben Root > > On Mon, Feb 19, 2018 at 9:37 AM, ?ric Depagne wrote: > > Le vendredi 16 f?vrier 2018, 21:41:07 SAST vincent.adrien at gmail.com a > > ?crit : > > Hi Adrien, > > > > Thanks for the answer, I'll have a look and will try to get things working > > a > > bit more efficiently. > > > > Cheers, > > ?ric. > > > > > Hi ?ric, > > > > > > I am not very used to play with interactive events, but I guess some > > > blitting could help you with performance: > > > - > > > https://stackoverflow.com/questions/29277080/efficient-> > > > matplotlib-redrawing > > > > > - > > > https://matplotlib.org/users/event_handling.html#draggable-> > > > rectangle-exercis > > > > > e (see the extra credit example) > > > > > > See the attached script that is inspired from your code and seems to > > > less stress my CPU. > > > > > > Hopefully this helps. > > > > > > Best, > > > Adrien > > > > > > On 02/16/2018 01:36 AM, ?ric Depagne wrote: > > > > Hi all, > > > > > > > > I have a gridspec plot and one of the subplot is a zoom on the part > > > > over > > > > > > which the mouse hovers on another subplot. > > > > > > > > It works, but I think the way I implemented it is not very efficient, > > > > since each time I use it, I see one CPU go to 100%. > > > > Here is the code that does implement the zoom. Any idea on how to make > > > > it > > > > > > (more) efficient or changes that I should implement welcome. > > > > > > > > Thanks. > > > > > > > > def plot(self): > > > > gs = gridspec.GridSpec(6, 2) > > > > ax1 = plt.subplot(gs[1:, 0]) > > > > plt1 = ax1.imshow(self.data, vmin=self.dataminzs, > > > > vmax=self.datamaxzs) > > > > ax1.set_label('AX1') > > > > self.ax2 = plt.subplot(gs[0:3, 1]) > > > > zoomeddata = self.data[np.int(self.data.shape[0]/ > > > > > > > > 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/ > > > > 2)-50:np.int(self.data.shape[1]/2)+50] > > > > > > > > self.plt2 = self.ax2.imshow(zoomeddata, vmin=self.dataminzs, > > > > > > > > vmax=self.datamaxzs) > > > > > > > > ax1.figure.canvas.mpl_connect('motion_notify_event', > > > > self._on_move) > > > > > > > > def _on_move(self, event): > > > > zoom1 = 100 > > > > > > > > if event.inaxes: > > > > ax = event.inaxes # the axes instance > > > > > > > > if 'AX1' in ax.get_label(): > > > > # Mouse is in subplot 1. > > > > xinf2 = np.int(event.xdata - zoom1) > > > > xsup2 = np.int(event.xdata + zoom1) > > > > yinf2 = np.int(event.ydata - zoom1) > > > > ysup2 = np.int(event.ydata + zoom1) > > > > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > > > > self.plt2.set_data(ax2data) > > > > self.ax2.figure.canvas.draw() > > > > -- > > Un clavier azerty en vaut deux > > ---------------------------------------------------------- > > ?ric Depagne > > > > > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users at python.org > > https://mail.python.org/mailman/listinfo/matplotlib-users -- Un clavier azerty en vaut deux ---------------------------------------------------------- ?ric Depagne From projetmbc at gmail.com Tue Feb 20 03:36:11 2018 From: projetmbc at gmail.com (Christophe Bal) Date: Tue, 20 Feb 2018 09:36:11 +0100 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: <1794988.hQncGMomWA@portable> References: <2718503.CSJC07vTRv@portable> <7872196.kKXBaVDImM@portable> <1794988.hQncGMomWA@portable> Message-ID: Hello. Can you post the final code for us ? Christophe BAL Enseignant Agr?g? de Math?matiques Programmeur Python Amateur Le 20 f?vr. 2018 09:01, "?ric Depagne" a ?crit : > Le lundi 19 f?vrier 2018, 17:04:28 SAST Benjamin Root a ?crit : > Hi Ben, > > Thanks for the idea. > I'll see how my code runs on a slower computer than mine, and I'll > implement > it should I find my current solution too slow. > > ?ric. > > > You might want to consider not having the limits change at *every* mouse > > motion over the axes. You can add a function state variable and maybe > have > > it refresh every other motion or so. > > > > ``` > > def _on_move(self, event): > > zoom1 = 100 > > if event.inaxes: > > > > ax = event.inaxes # the axes instance > > if 'AX1' in ax.get_label(): > > _on_move.counter += 1 > > if _on_move.counter % 2: > > return > > # Mouse is in subplot 1. > > xinf2 = np.int(event.xdata - zoom1) > > xsup2 = np.int(event.xdata + zoom1) > > yinf2 = np.int(event.ydata - zoom1) > > ysup2 = np.int(event.ydata + zoom1) > > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > > self.plt2.set_data(ax2data) > > self.ax2.figure.canvas.draw() > > _on_move.counter = 0 > > ``` > > Another approach could be done where you capture the timestamp of when > this > > function was last used for updating the limits, and only do a new limit > > update if a certain amount of time passed, such as half a second or so. > > > > Cheers! > > Ben Root > > > > On Mon, Feb 19, 2018 at 9:37 AM, ?ric Depagne wrote: > > > Le vendredi 16 f?vrier 2018, 21:41:07 SAST vincent.adrien at gmail.com a > > > ?crit : > > > Hi Adrien, > > > > > > Thanks for the answer, I'll have a look and will try to get things > working > > > a > > > bit more efficiently. > > > > > > Cheers, > > > ?ric. > > > > > > > Hi ?ric, > > > > > > > > I am not very used to play with interactive events, but I guess some > > > > blitting could help you with performance: > > > > - > > > > https://stackoverflow.com/questions/29277080/efficient-> > > > > matplotlib-redrawing > > > > > > > - > > > > https://matplotlib.org/users/event_handling.html#draggable-> > > > > rectangle-exercis > > > > > > > e (see the extra credit example) > > > > > > > > See the attached script that is inspired from your code and seems to > > > > less stress my CPU. > > > > > > > > Hopefully this helps. > > > > > > > > Best, > > > > Adrien > > > > > > > > On 02/16/2018 01:36 AM, ?ric Depagne wrote: > > > > > Hi all, > > > > > > > > > > I have a gridspec plot and one of the subplot is a zoom on the part > > > > > > over > > > > > > > > which the mouse hovers on another subplot. > > > > > > > > > > It works, but I think the way I implemented it is not very > efficient, > > > > > since each time I use it, I see one CPU go to 100%. > > > > > Here is the code that does implement the zoom. Any idea on how to > make > > > > > > it > > > > > > > > (more) efficient or changes that I should implement welcome. > > > > > > > > > > Thanks. > > > > > > > > > > def plot(self): > > > > > gs = gridspec.GridSpec(6, 2) > > > > > ax1 = plt.subplot(gs[1:, 0]) > > > > > plt1 = ax1.imshow(self.data, vmin=self.dataminzs, > > > > > vmax=self.datamaxzs) > > > > > ax1.set_label('AX1') > > > > > self.ax2 = plt.subplot(gs[0:3, 1]) > > > > > zoomeddata = self.data[np.int(self.data.shape[0]/ > > > > > > > > > > 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/ > > > > > 2)-50:np.int(self.data.shape[1]/2)+50] > > > > > > > > > > self.plt2 = self.ax2.imshow(zoomeddata, > vmin=self.dataminzs, > > > > > > > > > > vmax=self.datamaxzs) > > > > > > > > > > ax1.figure.canvas.mpl_connect('motion_notify_event', > > > > > self._on_move) > > > > > > > > > > def _on_move(self, event): > > > > > zoom1 = 100 > > > > > > > > > > if event.inaxes: > > > > > ax = event.inaxes # the axes instance > > > > > > > > > > if 'AX1' in ax.get_label(): > > > > > # Mouse is in subplot 1. > > > > > xinf2 = np.int(event.xdata - zoom1) > > > > > xsup2 = np.int(event.xdata + zoom1) > > > > > yinf2 = np.int(event.ydata - zoom1) > > > > > ysup2 = np.int(event.ydata + zoom1) > > > > > ax2data = self.data[yinf2:ysup2, xinf2:xsup2] > > > > > self.plt2.set_data(ax2data) > > > > > self.ax2.figure.canvas.draw() > > > > > > -- > > > Un clavier azerty en vaut deux > > > ---------------------------------------------------------- > > > ?ric Depagne > > > > > > > > > _______________________________________________ > > > Matplotlib-users mailing list > > > Matplotlib-users at python.org > > > https://mail.python.org/mailman/listinfo/matplotlib-users > > > -- > Un clavier azerty en vaut deux > ---------------------------------------------------------- > ?ric Depagne > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric at depagne.org Tue Feb 20 14:02:52 2018 From: eric at depagne.org (=?ISO-8859-1?Q?=C9ric?= Depagne) Date: Tue, 20 Feb 2018 21:02:52 +0200 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: References: <2718503.CSJC07vTRv@portable> <1794988.hQncGMomWA@portable> Message-ID: <3552955.lNGLj3qyV6@portable> Hi Christophe, I am not sure it's what Ben had in mind (if not, I'm happy to know how it should have been done), but here is the way I did it. (my _on_move() method is a member of a class) I added this to the __init__() : self.counter = 0 Then I added the following lines to _on_move(): self.counter += 1 if self.counter %2 : return [snip all the details of the update of the plots) self.counter = 0 And it updates the plot every other move. ?ric. -- Un clavier azerty en vaut deux ---------------------------------------------------------- ?ric Depagne From projetmbc at gmail.com Tue Feb 20 15:03:42 2018 From: projetmbc at gmail.com (Christophe Bal) Date: Tue, 20 Feb 2018 21:03:42 +0100 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: <3552955.lNGLj3qyV6@portable> References: <2718503.CSJC07vTRv@portable> <1794988.hQncGMomWA@portable> <3552955.lNGLj3qyV6@portable> Message-ID: Thanks Christophe BAL Enseignant Agr?g? de Math?matiques Programmeur Python Amateur Le 20 f?vr. 2018 20:02, "?ric Depagne" a ?crit : > Hi Christophe, > > I am not sure it's what Ben had in mind (if not, I'm happy to know how it > should have been done), but here is the way I did it. > > (my _on_move() method is a member of a class) > I added this to the __init__() : > self.counter = 0 > > Then I added the following lines to _on_move(): > self.counter += 1 > if self.counter %2 : > return > [snip all the details of the update of the plots) > self.counter = 0 > > And it updates the plot every other move. > > ?ric. > > -- > Un clavier azerty en vaut deux > ---------------------------------------------------------- > ?ric Depagne > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben.v.root at gmail.com Tue Feb 20 15:27:45 2018 From: ben.v.root at gmail.com (Benjamin Root) Date: Tue, 20 Feb 2018 15:27:45 -0500 Subject: [Matplotlib-users] Efficiency in connecting two subplot. In-Reply-To: References: <2718503.CSJC07vTRv@portable> <1794988.hQncGMomWA@portable> <3552955.lNGLj3qyV6@portable> Message-ID: Yup, that's pretty much it. Since you have it all in a class, then doing `self.counter` makes a lot of sense. You can also tune it accordingly to do only every 3rd, 4th, 5th or what-have-you. Cheers! Ben Root On Tue, Feb 20, 2018 at 3:03 PM, Christophe Bal wrote: > Thanks > > Christophe BAL > Enseignant Agr?g? de Math?matiques > Programmeur Python Amateur > > Le 20 f?vr. 2018 20:02, "?ric Depagne" a ?crit : > >> Hi Christophe, >> >> I am not sure it's what Ben had in mind (if not, I'm happy to know how it >> should have been done), but here is the way I did it. >> >> (my _on_move() method is a member of a class) >> I added this to the __init__() : >> self.counter = 0 >> >> Then I added the following lines to _on_move(): >> self.counter += 1 >> if self.counter %2 : >> return >> [snip all the details of the update of the plots) >> self.counter = 0 >> >> And it updates the plot every other move. >> >> ?ric. >> >> -- >> Un clavier azerty en vaut deux >> ---------------------------------------------------------- >> ?ric Depagne >> >> >> > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akkana at shallowsky.com Fri Feb 23 16:01:35 2018 From: akkana at shallowsky.com (Akkana Peck) Date: Fri, 23 Feb 2018 14:01:35 -0700 Subject: [Matplotlib-users] Legend labels and placement ignored? Message-ID: <20180223210135.GF1218@shallowsky.com> Hi -- I'm having a problem with the legend on one of two subplots. For each curve plotted on each subplot, I set label="something", and then I set subplot.legend(position). This works for ax2, but for ax1 it's ignored. I asked on #matplotlib on Freenode and was advised it looked like a bug and that I should report it. So I did, https://github.com/matplotlib/matplotlib/issues/10576 but I thought I'd ask here too, to see if I'm doing something wrong in the way I specify my legends. I pared the example program down to this: ======= import matplotlib.pyplot as plt from matplotlib import gridspec import numpy as np def plot_planet(): tde = np.array([-23.029638, -22.953653, -22.871279, -22.782548, -22.687498, -22.586167, -22.478597, -22.364832, -22.244918, -22.118904, -21.986842]) obliq_ra = [-3.67878, -3.97686, -4.27044, -4.55928, -4.84302, -5.12142, -5.39412, -5.66088, -5.92146, -6.17544, -6.42264] eccen_ra = [ 0.40722, 0.27366, 0.14028, 0.0072, -0.12558, -0.25788, -0.3897, -0.52098, -0.6516, -0.78162, -0.91086] true_ra = [-3.27156, -3.7032, -4.13016, -4.55208, -4.9686, -5.3793, -5.78382, -6.18186, -6.57306, -6.95706, -7.3335 ] fig = plt.figure(figsize=(12, 8)) # width, height in inches gs = gridspec.GridSpec(1, 2, width_ratios=[2.5, 1]) # Plot equations of time: ax1 = fig.add_subplot(gs[0]) ax1.plot(obliq_ra, label="obliquity", color="lightblue") ax1.plot(eccen_ra, label="eccentricity", color="pink") ax1.plot(true_ra, label="Eqn of Time", color="black") ax1.set_title("Equation of Time") ax1.legend("upper left") # Plot the analemma: ax2 = fig.add_subplot(gs[-1]) ax2.plot(obliq_ra, tde, label="obliquity", color="lightblue") ax2.plot(eccen_ra, tde, label="eccentricity", color="pink") ax2.plot(true_ra, tde, label="analemma", color="black") ax2.set_title("Analemma") ax2.legend(loc="upper right") plt.show() if __name__ == '__main__': plot_planet() ======= Here's what I see: http://shallowsky.com/tmp/mpl-legend.jpg Note that the left subplot (ax1) has the legend in the upper right even though I specified upper left, and that the labels are mysteriously u, p, and p -- I can't figure out where those labels are coming from but they're clearly not the ones I specified. Any idea how I could fix this? Thanks! ...Akkana From vincent.adrien at gmail.com Fri Feb 23 16:26:51 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Fri, 23 Feb 2018 13:26:51 -0800 Subject: [Matplotlib-users] Legend labels and placement ignored? In-Reply-To: <20180223210135.GF1218@shallowsky.com> References: <20180223210135.GF1218@shallowsky.com> Message-ID: <08ed41f3-f92f-30ee-2d47-22cd996a77a5@gmail.com> Hi Akkana, Just to be sure, did you try with ``` ax1.legend(loc="upper left") # instead of ax1.legend("upper left") ``` Best, Adrien On 02/23/2018 01:01 PM, Akkana Peck wrote: > Hi -- I'm having a problem with the legend on one of two subplots. > For each curve plotted on each subplot, I set label="something", > and then I set subplot.legend(position). This works for ax2, but > for ax1 it's ignored. > > I asked on #matplotlib on Freenode and was advised it looked like > a bug and that I should report it. So I did, > https://github.com/matplotlib/matplotlib/issues/10576 > but I thought I'd ask here too, to see if I'm doing something wrong > in the way I specify my legends. > > I pared the example program down to this: > > ======= > import matplotlib.pyplot as plt > from matplotlib import gridspec > import numpy as np > > def plot_planet(): > tde = np.array([-23.029638, -22.953653, -22.871279, -22.782548, -22.687498, -22.586167, -22.478597, -22.364832, -22.244918, -22.118904, -21.986842]) > > obliq_ra = [-3.67878, -3.97686, -4.27044, -4.55928, -4.84302, -5.12142, -5.39412, -5.66088, -5.92146, -6.17544, -6.42264] > eccen_ra = [ 0.40722, 0.27366, 0.14028, 0.0072, -0.12558, -0.25788, -0.3897, -0.52098, -0.6516, -0.78162, -0.91086] > true_ra = [-3.27156, -3.7032, -4.13016, -4.55208, -4.9686, -5.3793, -5.78382, -6.18186, -6.57306, -6.95706, -7.3335 ] > > fig = plt.figure(figsize=(12, 8)) # width, height in inches > > gs = gridspec.GridSpec(1, 2, width_ratios=[2.5, 1]) > > # Plot equations of time: > ax1 = fig.add_subplot(gs[0]) > ax1.plot(obliq_ra, label="obliquity", color="lightblue") > ax1.plot(eccen_ra, label="eccentricity", color="pink") > ax1.plot(true_ra, label="Eqn of Time", color="black") > ax1.set_title("Equation of Time") > ax1.legend("upper left") > > # Plot the analemma: > ax2 = fig.add_subplot(gs[-1]) > ax2.plot(obliq_ra, tde, label="obliquity", color="lightblue") > ax2.plot(eccen_ra, tde, label="eccentricity", color="pink") > ax2.plot(true_ra, tde, label="analemma", color="black") > ax2.set_title("Analemma") > ax2.legend(loc="upper right") > > plt.show() > > if __name__ == '__main__': > plot_planet() > ======= > > Here's what I see: http://shallowsky.com/tmp/mpl-legend.jpg > Note that the left subplot (ax1) has the legend in the upper right > even though I specified upper left, and that the labels are > mysteriously u, p, and p -- I can't figure out where those labels > are coming from but they're clearly not the ones I specified. > > Any idea how I could fix this? Thanks! > > ...Akkana > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > From akkana at shallowsky.com Fri Feb 23 16:57:09 2018 From: akkana at shallowsky.com (Akkana Peck) Date: Fri, 23 Feb 2018 14:57:09 -0700 Subject: [Matplotlib-users] Legend labels and placement ignored? In-Reply-To: <08ed41f3-f92f-30ee-2d47-22cd996a77a5@gmail.com> References: <20180223210135.GF1218@shallowsky.com> <08ed41f3-f92f-30ee-2d47-22cd996a77a5@gmail.com> Message-ID: <20180223215709.GJ1218@shallowsky.com> That's it! Adding loc= fixes the problem. Many thanks! So I guess the u, p and p were coming from iterating over the string "upper left". How funny! (Funny now that it's solved, anyway. :-) ...Akkana vincent.adrien at gmail.com writes: > Hi Akkana, > > Just to be sure, did you try with > ``` > ax1.legend(loc="upper left") # instead of ax1.legend("upper left") > ``` > > Best, > Adrien > > On 02/23/2018 01:01 PM, Akkana Peck wrote: > > Hi -- I'm having a problem with the legend on one of two subplots. > > For each curve plotted on each subplot, I set label="something", > > and then I set subplot.legend(position). This works for ax2, but > > for ax1 it's ignored. > > > > I asked on #matplotlib on Freenode and was advised it looked like > > a bug and that I should report it. So I did, > > https://github.com/matplotlib/matplotlib/issues/10576 > > but I thought I'd ask here too, to see if I'm doing something wrong > > in the way I specify my legends. > > > > I pared the example program down to this: > > > > ======= > > import matplotlib.pyplot as plt > > from matplotlib import gridspec > > import numpy as np > > > > def plot_planet(): > > tde = np.array([-23.029638, -22.953653, -22.871279, -22.782548, -22.687498, -22.586167, -22.478597, -22.364832, -22.244918, -22.118904, -21.986842]) > > > > obliq_ra = [-3.67878, -3.97686, -4.27044, -4.55928, -4.84302, -5.12142, -5.39412, -5.66088, -5.92146, -6.17544, -6.42264] > > eccen_ra = [ 0.40722, 0.27366, 0.14028, 0.0072, -0.12558, -0.25788, -0.3897, -0.52098, -0.6516, -0.78162, -0.91086] > > true_ra = [-3.27156, -3.7032, -4.13016, -4.55208, -4.9686, -5.3793, -5.78382, -6.18186, -6.57306, -6.95706, -7.3335 ] > > > > fig = plt.figure(figsize=(12, 8)) # width, height in inches > > > > gs = gridspec.GridSpec(1, 2, width_ratios=[2.5, 1]) > > > > # Plot equations of time: > > ax1 = fig.add_subplot(gs[0]) > > ax1.plot(obliq_ra, label="obliquity", color="lightblue") > > ax1.plot(eccen_ra, label="eccentricity", color="pink") > > ax1.plot(true_ra, label="Eqn of Time", color="black") > > ax1.set_title("Equation of Time") > > ax1.legend("upper left") > > > > # Plot the analemma: > > ax2 = fig.add_subplot(gs[-1]) > > ax2.plot(obliq_ra, tde, label="obliquity", color="lightblue") > > ax2.plot(eccen_ra, tde, label="eccentricity", color="pink") > > ax2.plot(true_ra, tde, label="analemma", color="black") > > ax2.set_title("Analemma") > > ax2.legend(loc="upper right") > > > > plt.show() > > > > if __name__ == '__main__': > > plot_planet() > > ======= > > > > Here's what I see: http://shallowsky.com/tmp/mpl-legend.jpg > > Note that the left subplot (ax1) has the legend in the upper right > > even though I specified upper left, and that the labels are > > mysteriously u, p, and p -- I can't figure out where those labels > > are coming from but they're clearly not the ones I specified. > > > > Any idea how I could fix this? Thanks! > > > > ...Akkana > > _______________________________________________ > > Matplotlib-users mailing list > > Matplotlib-users at python.org > > https://mail.python.org/mailman/listinfo/matplotlib-users > > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users From vincent.adrien at gmail.com Fri Feb 23 17:50:04 2018 From: vincent.adrien at gmail.com (vincent.adrien at gmail.com) Date: Fri, 23 Feb 2018 14:50:04 -0800 Subject: [Matplotlib-users] Legend labels and placement ignored? In-Reply-To: <20180223215709.GJ1218@shallowsky.com> References: <20180223210135.GF1218@shallowsky.com> <08ed41f3-f92f-30ee-2d47-22cd996a77a5@gmail.com> <20180223215709.GJ1218@shallowsky.com> Message-ID: <2baa6371-1ed4-f990-edb9-21fec88db9c7@gmail.com> Yes, my guess is that it was using the signature `legend(labels, *kwargs)`, where `loc` is expected as a *keyword* (not a positional) argument. Thus the string was taken as the list of the desired labels and `loc` was defaulting to "best". Best, Adrien On 02/23/2018 01:57 PM, Akkana Peck wrote: > That's it! Adding loc= fixes the problem. Many thanks! > > So I guess the u, p and p were coming from iterating over the string > "upper left". How funny! (Funny now that it's solved, anyway. :-) > > ...Akkana > > vincent.adrien at gmail.com writes: >> Hi Akkana, >> >> Just to be sure, did you try with >> ``` >> ax1.legend(loc="upper left") # instead of ax1.legend("upper left") >> ``` >> >> Best, >> Adrien >> >> On 02/23/2018 01:01 PM, Akkana Peck wrote: >>> Hi -- I'm having a problem with the legend on one of two subplots. >>> For each curve plotted on each subplot, I set label="something", >>> and then I set subplot.legend(position). This works for ax2, but >>> for ax1 it's ignored. >>> >>> I asked on #matplotlib on Freenode and was advised it looked like >>> a bug and that I should report it. So I did, >>> https://github.com/matplotlib/matplotlib/issues/10576 >>> but I thought I'd ask here too, to see if I'm doing something wrong >>> in the way I specify my legends. >>> >>> I pared the example program down to this: >>> >>> ======= >>> import matplotlib.pyplot as plt >>> from matplotlib import gridspec >>> import numpy as np >>> >>> def plot_planet(): >>> tde = np.array([-23.029638, -22.953653, -22.871279, -22.782548, -22.687498, -22.586167, -22.478597, -22.364832, -22.244918, -22.118904, -21.986842]) >>> >>> obliq_ra = [-3.67878, -3.97686, -4.27044, -4.55928, -4.84302, -5.12142, -5.39412, -5.66088, -5.92146, -6.17544, -6.42264] >>> eccen_ra = [ 0.40722, 0.27366, 0.14028, 0.0072, -0.12558, -0.25788, -0.3897, -0.52098, -0.6516, -0.78162, -0.91086] >>> true_ra = [-3.27156, -3.7032, -4.13016, -4.55208, -4.9686, -5.3793, -5.78382, -6.18186, -6.57306, -6.95706, -7.3335 ] >>> >>> fig = plt.figure(figsize=(12, 8)) # width, height in inches >>> >>> gs = gridspec.GridSpec(1, 2, width_ratios=[2.5, 1]) >>> >>> # Plot equations of time: >>> ax1 = fig.add_subplot(gs[0]) >>> ax1.plot(obliq_ra, label="obliquity", color="lightblue") >>> ax1.plot(eccen_ra, label="eccentricity", color="pink") >>> ax1.plot(true_ra, label="Eqn of Time", color="black") >>> ax1.set_title("Equation of Time") >>> ax1.legend("upper left") >>> >>> # Plot the analemma: >>> ax2 = fig.add_subplot(gs[-1]) >>> ax2.plot(obliq_ra, tde, label="obliquity", color="lightblue") >>> ax2.plot(eccen_ra, tde, label="eccentricity", color="pink") >>> ax2.plot(true_ra, tde, label="analemma", color="black") >>> ax2.set_title("Analemma") >>> ax2.legend(loc="upper right") >>> >>> plt.show() >>> >>> if __name__ == '__main__': >>> plot_planet() >>> ======= >>> >>> Here's what I see: http://shallowsky.com/tmp/mpl-legend.jpg >>> Note that the left subplot (ax1) has the legend in the upper right >>> even though I specified upper left, and that the labels are >>> mysteriously u, p, and p -- I can't figure out where those labels >>> are coming from but they're clearly not the ones I specified. >>> >>> Any idea how I could fix this? Thanks! >>> >>> ...Akkana >>> _______________________________________________ >>> Matplotlib-users mailing list >>> Matplotlib-users at python.org >>> https://mail.python.org/mailman/listinfo/matplotlib-users >>> >> >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users >