[Matplotlib-users] Problem with text bounding box
Recently, I switched from matplotlib 0.99 to 1.0.1 and unfortunately discovered that my text scaling script stopped working properly. The script scales the given text to fit into the current figure. A quick example of what I'm doing (works in 0.99, but not in 1.0.1 and 1.1.1rc): import matplotlib.pyplot as plt plt.ion() fig = plt.figure(1, (6,8), dpi=72) fig.add_axes([0,0,1,1]) txt1 = plt.text(0.5,0.5,'foobar',horizontalalignment='center',verticalalignment='center') plt.draw() # compute width of figure in points and divide by txt1 bounding box width sf1 = 6*72./txt1.cached.items()[0][1][1][0][1][0] txt1.set_size(txt1.get_size()*sf1) plt.draw() The problem is related to the fact that starting from mpl 1.0.1, the txt1.cached dictionary contains information of all text objects present rather than only of the specific object. I guess this behavior is intended, however this way it is rather complicated to derive the bounding box of the specific text object without cycling over the whole dictionary. Is there a different way to achieve a fitted text object? Thanks, br Jakob -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] how to avoid import backend in the batch job?
Dear all, I have a module written by myself which use python-netcdf/matplotlib/numpy/basemap for treating and mapping of netcdf files. so in the module I have a line: import matplotlib.pyplot as plt But now I am using some function of this module which do not involve the visualisation. And I want to use it in a batch mode submitted by qsub command. And then I have traceback like following: File /home/orchidee01/ychao/SCRIPT/combine.py, line 1, in module import gnc File /home/users/ychao/python/python_lib/gnc.py, line 4, in module import matplotlib.pyplot as plt File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/pyplot.py, line 95, in module new_figure_manager, draw_if_interactive, _show = pylab_setup() File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/__init__.py, line 25, in pylab_setup globals(),locals(),[backend_name]) File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py, line 10, in module from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\ File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py, line 8, in module import gtk; gdk = gtk.gdk File /usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py, line 64, in module _init() File /usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py, line 52, in _init _gtk.init_check() RuntimeError: could not open display From the last line, I think this is because I cannot use this module in a non-interactive mode. So is there a way I can bypass this issue and still use the module in a non-interactive mode? Thanks a lot for any information. Chao -- *** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16 -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to avoid import backend in the batch job?
On Monday, September 3, 2012, Chao YUE wrote: Dear all, I have a module written by myself which use python-netcdf/matplotlib/numpy/basemap for treating and mapping of netcdf files. so in the module I have a line: import matplotlib.pyplot as plt But now I am using some function of this module which do not involve the visualisation. And I want to use it in a batch mode submitted by qsub command. And then I have traceback like following: File /home/orchidee01/ychao/SCRIPT/combine.py, line 1, in module import gnc File /home/users/ychao/python/python_lib/gnc.py, line 4, in module import matplotlib.pyplot as plt File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/pyplot.py, line 95, in module new_figure_manager, draw_if_interactive, _show = pylab_setup() File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/__init__.py, line 25, in pylab_setup globals(),locals(),[backend_name]) File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py, line 10, in module from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\ File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py, line 8, in module import gtk; gdk = gtk.gdk File /usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py, line 64, in module _init() File /usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py, line 52, in _init _gtk.init_check() RuntimeError: could not open display From the last line, I think this is because I cannot use this module in a non-interactive mode. So is there a way I can bypass this issue and still use the module in a non-interactive mode? Thanks a lot for any information. Chao import matplotlib matplotlib.use(AGG) Or set that in the matplotlibrc file. Cheers, Ben Root -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] A sad day for our community. John Hunter: 1968-2012.
On 8/29/2012 10:32 PM, Fernando Perez wrote: http://numfocus.org/johnhunter My thanks to NumFOCUS for setting up this memorial fund so that Matplotlib users can say thank you to John. Alan Isaac -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to avoid import backend in the batch job?
Hi Ben, I changed the backend in matplotlibrc file. It works fine. Yet if I don't want to change the rc file, I guess I must change in the modules where matplotlib has been imported for the first time? cheers, Chao On Mon, Sep 3, 2012 at 3:30 PM, Benjamin Root ben.r...@ou.edu wrote: On Monday, September 3, 2012, Chao YUE wrote: Dear all, I have a module written by myself which use python-netcdf/matplotlib/numpy/basemap for treating and mapping of netcdf files. so in the module I have a line: import matplotlib.pyplot as plt But now I am using some function of this module which do not involve the visualisation. And I want to use it in a batch mode submitted by qsub command. And then I have traceback like following: File /home/orchidee01/ychao/SCRIPT/combine.py, line 1, in module import gnc File /home/users/ychao/python/python_lib/gnc.py, line 4, in module import matplotlib.pyplot as plt File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/pyplot.py, line 95, in module new_figure_manager, draw_if_interactive, _show = pylab_setup() File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/__init__.py, line 25, in pylab_setup globals(),locals(),[backend_name]) File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py, line 10, in module from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\ File /usr/local/install/matplotlib-1.1.0/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py, line 8, in module import gtk; gdk = gtk.gdk File /usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py, line 64, in module _init() File /usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py, line 52, in _init _gtk.init_check() RuntimeError: could not open display From the last line, I think this is because I cannot use this module in a non-interactive mode. So is there a way I can bypass this issue and still use the module in a non-interactive mode? Thanks a lot for any information. Chao import matplotlib matplotlib.use(AGG) Or set that in the matplotlibrc file. Cheers, Ben Root -- *** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16 -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to avoid import backend in the batch job?
On Mon, Sep 3, 2012 at 6:08 PM, Chao YUE chaoyue...@gmail.com wrote: Yet if I don't want to change the rc file, I guess I must change in the modules where matplotlib has been imported for the first time? If you're changing the rc file in your home directory: ~/.matplotlib/matplotlibrc then just make a copy before you change it: cd ~/.matplotlib cp matplotlibrc matplotlibrc_orig then edit matplotlibrc. Just rename matplotlibrc_orig back to matplotlibrc when you're done. -- Damon McDougall http://www.damon.is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Problem with text bounding box
On 2012/09/03 1:38 AM, Jakob Gager wrote: Recently, I switched from matplotlib 0.99 to 1.0.1 and unfortunately discovered that my text scaling script stopped working properly. The script scales the given text to fit into the current figure. A quick example of what I'm doing (works in 0.99, but not in 1.0.1 and 1.1.1rc): import matplotlib.pyplot as plt plt.ion() fig = plt.figure(1, (6,8), dpi=72) fig.add_axes([0,0,1,1]) txt1 = plt.text(0.5,0.5,'foobar',horizontalalignment='center',verticalalignment='center') plt.draw() # compute width of figure in points and divide by txt1 bounding box width sf1 = 6*72./txt1.cached.items()[0][1][1][0][1][0] txt1.set_size(txt1.get_size()*sf1) plt.draw() The problem is related to the fact that starting from mpl 1.0.1, the txt1.cached dictionary contains information of all text objects present rather than only of the specific object. I guess this behavior is intended, however this way it is rather complicated to derive the bounding box of the specific text object without cycling over the whole dictionary. It looks like you can either use the _get_layout() method (which requires that you specify the renderer), or, if you know the text object will be among the last 50 for which _get_layout() has been called, you can use txt1.cached[txt1.get_prop_typ()]. Is there a different way to achieve a fitted text object? Not that I know of; but someone else may have a suggestion. Eric Thanks, br Jakob -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] animation framework problem
Hi, I am trying to create a multi-subplot animation with based loosely on the animation example code, subplots.py, at http://matplotlib.sourceforge.net/examples/animation/subplots.html A simplified version of the full code is shown at this gist: https://gist.github.com/3613113 I am having problems getting the code to function properly. If I run it as is, the figure appears, but no animation is done. Apparently the setup code is called, but the code to change the frames is not. If I comment out the call to the setup code, the method to update the frame is called once, and that is it. I would appreciate any help and insights that you can provide. Thank you very much. -g -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to avoid import backend in the batch job?
Thanks Damon, it's very clear now. I explicit set the backend as GTKAgg in my ipython user configuration file. and always set the backend to 'Agg' in my rc file. So that when I use ipython, I can see the window interactively, but when I use script, it also works :P Chao On Mon, Sep 3, 2012 at 8:13 PM, Damon McDougall damon.mcdoug...@gmail.comwrote: On Mon, Sep 3, 2012 at 6:08 PM, Chao YUE chaoyue...@gmail.com wrote: Yet if I don't want to change the rc file, I guess I must change in the modules where matplotlib has been imported for the first time? If you're changing the rc file in your home directory: ~/.matplotlib/matplotlibrc then just make a copy before you change it: cd ~/.matplotlib cp matplotlibrc matplotlibrc_orig then edit matplotlibrc. Just rename matplotlibrc_orig back to matplotlibrc when you're done. -- Damon McDougall http://www.damon.is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom -- *** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16 -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to avoid import backend in the batch job?
On Mon, Sep 3, 2012 at 10:20 PM, Chao YUE chaoyue...@gmail.com wrote: Thanks Damon, it's very clear now. I explicit set the backend as GTKAgg in my ipython user configuration file. and always set the backend to 'Agg' in my rc file. So that when I use ipython, I can see the window interactively, but when I use script, it also works :P That's an awesome idea. Glad it's working now. Chao On Mon, Sep 3, 2012 at 8:13 PM, Damon McDougall damon.mcdoug...@gmail.com wrote: On Mon, Sep 3, 2012 at 6:08 PM, Chao YUE chaoyue...@gmail.com wrote: Yet if I don't want to change the rc file, I guess I must change in the modules where matplotlib has been imported for the first time? If you're changing the rc file in your home directory: ~/.matplotlib/matplotlibrc then just make a copy before you change it: cd ~/.matplotlib cp matplotlibrc matplotlibrc_orig then edit matplotlibrc. Just rename matplotlibrc_orig back to matplotlibrc when you're done. -- Damon McDougall http://www.damon.is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom -- *** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16 -- Damon McDougall http://www.damon.is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users