##// END OF EJS Templates
add `%pylab --no-import`...
MinRK -
Show More
@@ -1,88 +1,109 b''
1 """Implementation of magic functions for matplotlib/pylab support.
1 """Implementation of magic functions for matplotlib/pylab support.
2 """
2 """
3 #-----------------------------------------------------------------------------
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2012 The IPython Development Team.
4 # Copyright (c) 2012 The IPython Development Team.
5 #
5 #
6 # Distributed under the terms of the Modified BSD License.
6 # Distributed under the terms of the Modified BSD License.
7 #
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
10
10
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 # Our own packages
15 # Our own packages
16 from IPython.config.application import Application
16 from IPython.config.application import Application
17 from IPython.core import magic_arguments
17 from IPython.core.magic import Magics, magics_class, line_magic
18 from IPython.core.magic import Magics, magics_class, line_magic
18 from IPython.testing.skipdoctest import skip_doctest
19 from IPython.testing.skipdoctest import skip_doctest
19
20
20 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
21 # Magic implementation classes
22 # Magic implementation classes
22 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
23
24
24 @magics_class
25 @magics_class
25 class PylabMagics(Magics):
26 class PylabMagics(Magics):
26 """Magics related to matplotlib's pylab support"""
27 """Magics related to matplotlib's pylab support"""
27
28
28 @skip_doctest
29 @skip_doctest
29 @line_magic
30 @line_magic
30 def pylab(self, parameter_s=''):
31 @magic_arguments.magic_arguments()
32 @magic_arguments.argument(
33 '--no-import', action='store_true', default=None,
34 help="""Prevent IPython from populating the namespace"""
35 )
36 @magic_arguments.argument(
37 'gui', nargs='?',
38 help="""Name of the matplotlib backend to use
39 ('qt', 'wx', 'gtk', 'osx', 'tk', 'inline', 'auto').
40 If given, the corresponding matplotlib backend is used,
41 otherwise it will be matplotlib's default
42 (which you can set in your matplotlib config file).
43 """
44 )
45 def pylab(self, line=''):
31 """Load numpy and matplotlib to work interactively.
46 """Load numpy and matplotlib to work interactively.
32
47
33 %pylab [GUINAME]
48 %pylab [GUINAME]
34
49
35 This function lets you activate pylab (matplotlib, numpy and
50 This function lets you activate pylab (matplotlib, numpy and
36 interactive support) at any point during an IPython session.
51 interactive support) at any point during an IPython session.
37
52
38 It will import at the top level numpy as np, pyplot as plt, matplotlib,
53 It will import at the top level numpy as np, pyplot as plt, matplotlib,
39 pylab and mlab, as well as all names from numpy and pylab.
54 pylab and mlab, as well as all names from numpy and pylab.
40
55
41 If you are using the inline matplotlib backend for embedded figures,
56 If you are using the inline matplotlib backend for embedded figures,
42 you can adjust its behavior via the %config magic::
57 you can adjust its behavior via the %config magic::
43
58
44 # enable SVG figures, necessary for SVG+XHTML export in the qtconsole
59 # enable SVG figures, necessary for SVG+XHTML export in the qtconsole
45 In [1]: %config InlineBackend.figure_format = 'svg'
60 In [1]: %config InlineBackend.figure_format = 'svg'
46
61
47 # change the behavior of closing all figures at the end of each
62 # change the behavior of closing all figures at the end of each
48 # execution (cell), or allowing reuse of active figures across
63 # execution (cell), or allowing reuse of active figures across
49 # cells:
64 # cells:
50 In [2]: %config InlineBackend.close_figures = False
65 In [2]: %config InlineBackend.close_figures = False
51
66
52 Parameters
67 Parameters
53 ----------
68 ----------
54 guiname : optional
69 guiname : optional
55 One of the valid arguments to the %gui magic ('qt', 'wx', 'gtk',
70 One of the valid arguments to the %gui magic ('qt', 'wx', 'gtk',
56 'osx' or 'tk'). If given, the corresponding Matplotlib backend is
71 'osx' or 'tk'). If given, the corresponding Matplotlib backend is
57 used, otherwise matplotlib's default (which you can override in your
72 used, otherwise matplotlib's default (which you can override in your
58 matplotlib config file) is used.
73 matplotlib config file) is used.
59
74
60 Examples
75 Examples
61 --------
76 --------
62 In this case, where the MPL default is TkAgg::
77 In this case, where the MPL default is TkAgg::
63
78
64 In [2]: %pylab
79 In [2]: %pylab
65
80
66 Welcome to pylab, a matplotlib-based Python environment.
81 Welcome to pylab, a matplotlib-based Python environment.
67 Backend in use: TkAgg
82 Backend in use: TkAgg
68 For more information, type 'help(pylab)'.
83 For more information, type 'help(pylab)'.
69
84
70 But you can explicitly request a different backend::
85 But you can explicitly request a different backend::
71
86
72 In [3]: %pylab qt
87 In [3]: %pylab qt
73
88
74 Welcome to pylab, a matplotlib-based Python environment.
89 Welcome to pylab, a matplotlib-based Python environment.
75 Backend in use: Qt4Agg
90 Backend in use: Qt4Agg
76 For more information, type 'help(pylab)'.
91 For more information, type 'help(pylab)'.
77 """
92 """
78
93 args = magic_arguments.parse_argstring(self.pylab, line)
79 if Application.initialized():
94 if args.no_import is None:
80 app = Application.instance()
95 # get default from Application
81 try:
96 if Application.initialized():
82 import_all_status = app.pylab_import_all
97 app = Application.instance()
83 except AttributeError:
98 try:
84 import_all_status = True
99 import_all = app.pylab_import_all
100 except AttributeError:
101 import_all = True
102 else:
103 # nothing specified, no app - default True
104 import_all = True
85 else:
105 else:
86 import_all_status = True
106 # invert no-import flag
107 import_all = not args.no_import
87
108
88 self.shell.enable_pylab(parameter_s, import_all=import_all_status, welcome_message=True)
109 self.shell.enable_pylab(args.gui, import_all=import_all, welcome_message=True)
General Comments 0
You need to be logged in to leave comments. Login now