
On Thu, Jul 26, 2012 at 4:45 PM, Colin J. Williams <fn681@ncf.ca> wrote:
It seems that these standards have been adopted, which is good:
The following import conventions are used throughout the NumPy source and documentation:
import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt
Source: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
Is there some similar standard for PyLab?
Thanks,
Colin W.
Colin, Typically, with pylab mode of matplotlib, you do: from pylab import * This is essentially equivalent to: from numpy import * from matplotlib.pyplot import * Note that the pylab "module" is actually a part of matplotlib and is a shortcut to provide an environment that is very familiar to Matlab users. Converts are then encouraged to use the imports you mentioned in order to properly utilize python namespaces. I hope that helps! Ben Root

On Fri, Jul 27, 2012 at 12:05 AM, Colin J. Williams <cjwilliams43@gmail.com> wrote:
On 26/07/2012 4:57 PM, Benjamin Root wrote:
On Thu, Jul 26, 2012 at 4:45 PM, Colin J. Williams <fn681@ncf.ca> wrote:
It seems that these standards have been adopted, which is good:
The following import conventions are used throughout the NumPy source and documentation:
import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt
Source: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
Is there some similar standard for PyLab?
Thanks,
Colin W.
Colin,
Typically, with pylab mode of matplotlib, you do:
from pylab import *
This is essentially equivalent to:
from numpy import * from matplotlib.pyplot import *
Note that the pylab "module" is actually a part of matplotlib and is a shortcut to provide an environment that is very familiar to Matlab users. Converts are then encouraged to use the imports you mentioned in order to properly utilize python namespaces.
I hope that helps! Ben Root
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Thanks Ben,
I would prefer not to use: from xxx import *,
because of the name pollution.
The name convention that I copied above facilitates avoiding the pollution.
In the same spirit, I've used: import pylab as plb
But in that same spirit, using np and plt separately is preferred. -- Robert Kern

On Thu, Jul 26, 2012 at 7:12 PM, Robert Kern <robert.kern@gmail.com> wrote:
On 26/07/2012 4:57 PM, Benjamin Root wrote:
On Thu, Jul 26, 2012 at 4:45 PM, Colin J. Williams <fn681@ncf.ca> wrote:
It seems that these standards have been adopted, which is good:
The following import conventions are used throughout the NumPy source
and
documentation:
import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt
Source: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
Is there some similar standard for PyLab?
Thanks,
Colin W.
Colin,
Typically, with pylab mode of matplotlib, you do:
from pylab import *
This is essentially equivalent to:
from numpy import * from matplotlib.pyplot import *
Note that the pylab "module" is actually a part of matplotlib and is a shortcut to provide an environment that is very familiar to Matlab users. Converts are then encouraged to use the imports you mentioned in order to properly utilize python namespaces.
I hope that helps! Ben Root
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Thanks Ben,
I would prefer not to use: from xxx import *,
because of the name pollution.
The name convention that I copied above facilitates avoiding the
On Fri, Jul 27, 2012 at 12:05 AM, Colin J. Williams <cjwilliams43@gmail.com> wrote: pollution.
In the same spirit, I've used: import pylab as plb
But in that same spirit, using np and plt separately is preferred.
"Namespaces are one honking great idea -- let's do more of those!" from http://www.python.org/dev/peps/pep-0020/ Absolutely correct. The namespace pollution is exactly why we encourage converts to move over from the pylab mode to separating out the numpy and pyplot namespaces. There are very subtle issues that arise when doing "from pylab import *" such as overriding the built-in "any" and "all". The only real advantage of the pylab mode over separating out numpy and pyplot is conciseness, which many matlab users expect at first. Cheers! Ben Root

On 27.07.2012, at 3:27PM, Benjamin Root wrote:
I would prefer not to use: from xxx import *,
because of the name pollution.
The name convention that I copied above facilitates avoiding the pollution.
In the same spirit, I've used: import pylab as plb
But in that same spirit, using np and plt separately is preferred.
"Namespaces are one honking great idea -- let's do more of those!" from http://www.python.org/dev/peps/pep-0020/
Absolutely correct. The namespace pollution is exactly why we encourage converts to move over from the pylab mode to separating out the numpy and pyplot namespaces. There are very subtle issues that arise when doing "from pylab import *" such as overriding the built-in "any" and "all". The only real advantage of the pylab mode over separating out numpy and pyplot is conciseness, which many matlab users expect at first.
It unfortunately also comes with the convenience of using the "ipython --pylab" mode - does anyone know how to turn the "import *" part of, or how to create a similar working environment with ipython that does keep namespaces clean? Cheers, Derek

On Fri, Jul 27, 2012 at 11:39 AM, Derek Homeier < derek@astro.physik.uni-goettingen.de> wrote:
On 27.07.2012, at 3:27PM, Benjamin Root wrote:
I would prefer not to use: from xxx import *,
because of the name pollution.
The name convention that I copied above facilitates avoiding the pollution.
In the same spirit, I've used: import pylab as plb
But in that same spirit, using np and plt separately is preferred.
"Namespaces are one honking great idea -- let's do more of those!" from http://www.python.org/dev/peps/pep-0020/
Absolutely correct. The namespace pollution is exactly why we encourage converts to move over from the pylab mode to separating out the numpy and pyplot namespaces. There are very subtle issues that arise when doing "from pylab import *" such as overriding the built-in "any" and "all". The only real advantage of the pylab mode over separating out numpy and pyplot is conciseness, which many matlab users expect at first.
It unfortunately also comes with the convenience of using the "ipython --pylab" mode - does anyone know how to turn the "import *" part of, or how to create a similar working environment with ipython that does keep namespaces clean?
Cheers, Derek
There's a config flag that you can add to your ipython profile: c.TerminalIPythonApp.pylab_import_all = False For example, my profile is in ~/.ipython/profile_default/ipython_config.py Cheers, -Tony

On 27 Jul 2012, at 17:58, Tony Yu wrote:
On Fri, Jul 27, 2012 at 11:39 AM, Derek Homeier <derek@astro.physik.uni-goettingen.de> wrote: On 27.07.2012, at 3:27PM, Benjamin Root wrote:
I would prefer not to use: from xxx import *,
because of the name pollution.
The name convention that I copied above facilitates avoiding the pollution.
In the same spirit, I've used: import pylab as plb
But in that same spirit, using np and plt separately is preferred.
"Namespaces are one honking great idea -- let's do more of those!" from http://www.python.org/dev/peps/pep-0020/
Absolutely correct. The namespace pollution is exactly why we encourage converts to move over from the pylab mode to separating out the numpy and pyplot namespaces. There are very subtle issues that arise when doing "from pylab import *" such as overriding the built-in "any" and "all". The only real advantage of the pylab mode over separating out numpy and pyplot is conciseness, which many matlab users expect at first.
It unfortunately also comes with the convenience of using the "ipython --pylab" mode - does anyone know how to turn the "import *" part of, or how to create a similar working environment with ipython that does keep namespaces clean?
Cheers, Derek
There's a config flag that you can add to your ipython profile:
c.TerminalIPythonApp.pylab_import_all = False
For example, my profile is in ~/.ipython/profile_default/ipython_config.py
thanks, that was exactly what I was looking for - together with c.TerminalIPythonApp.exec_lines = ['import sys', 'import numpy as np', 'import matplotlib as mpl', 'import matplotlib.pyplot as plt'] etc. to have the shortcuts. Cheers, Derek

On Fri, Jul 27, 2012 at 9:43 AM, Derek Homeier <derek@astro.physik.uni-goettingen.de> wrote:
thanks, that was exactly what I was looking for - together with
c.TerminalIPythonApp.exec_lines = ['import sys', 'import numpy as np', 'import matplotlib as mpl', 'import matplotlib.pyplot as plt']
Note that if you do this only and don't use %pylab interactively or the --pylab flag, then you will *not* get the proper non-blocking control of the matplotlib event loop integrated with the terminal or qtconsole. In summary, following Tony's suggestion is enough to give you: - event loop integration when you do --pylab at the prompt or %pylab in ipython. - the np, mpl and plt shortcuts - no 'import *' at all. So that should be sufficient, but you should still use --pylab or %pylab to indicate to IPython that you want the mpl event loops to work in conjunction with the shell. Cheers, f

On 27.07.2012, at 8:30PM, Fernando Perez <fperez.net@gmail.com> wrote:
On Fri, Jul 27, 2012 at 9:43 AM, Derek Homeier <derek@astro.physik.uni-goettingen.de> wrote:
thanks, that was exactly what I was looking for - together with
c.TerminalIPythonApp.exec_lines = ['import sys', 'import numpy as np', 'import matplotlib as mpl', 'import matplotlib.pyplot as plt']
Note that if you do this only and don't use %pylab interactively or the --pylab flag, then you will *not* get the proper non-blocking control of the matplotlib event loop integrated with the terminal or qtconsole.
In summary, following Tony's suggestion is enough to give you:
- event loop integration when you do --pylab at the prompt or %pylab in ipython. - the np, mpl and plt shortcuts - no 'import *' at all.
So that should be sufficient, but you should still use --pylab or %pylab to indicate to IPython that you want the mpl event loops to work in conjunction with the shell.
Yes, I was aware of that, without the pylab option at least with the macosx backend windows either would not draw and refresh properly, or block the shell after a draw() or show(); that's why I was asking how to avoid the 'import *' with it. I have not used the %pylab builtin before, though. Cheers, Derek
participants (7)
-
Benjamin Root
-
Colin J. Williams
-
Colin J. Williams
-
Derek Homeier
-
Fernando Perez
-
Robert Kern
-
Tony Yu