Show More
@@ -0,0 +1,88 b'' | |||
|
1 | """Implementation of magic functions for matplotlib/pylab support. | |
|
2 | """ | |
|
3 | #----------------------------------------------------------------------------- | |
|
4 | # Copyright (c) 2012 The IPython Development Team. | |
|
5 | # | |
|
6 | # Distributed under the terms of the Modified BSD License. | |
|
7 | # | |
|
8 | # The full license is in the file COPYING.txt, distributed with this software. | |
|
9 | #----------------------------------------------------------------------------- | |
|
10 | ||
|
11 | #----------------------------------------------------------------------------- | |
|
12 | # Imports | |
|
13 | #----------------------------------------------------------------------------- | |
|
14 | ||
|
15 | # Our own packages | |
|
16 | from IPython.config.application import Application | |
|
17 | from IPython.core.magic import Magics, register_magics, line_magic | |
|
18 | from IPython.testing.skipdoctest import skip_doctest | |
|
19 | ||
|
20 | #----------------------------------------------------------------------------- | |
|
21 | # Magic implementation classes | |
|
22 | #----------------------------------------------------------------------------- | |
|
23 | ||
|
24 | @register_magics | |
|
25 | class PylabMagics(Magics): | |
|
26 | """Magics related to matplotlib's pylab support""" | |
|
27 | ||
|
28 | @skip_doctest | |
|
29 | @line_magic | |
|
30 | def pylab(self, parameter_s=''): | |
|
31 | """Load numpy and matplotlib to work interactively. | |
|
32 | ||
|
33 | %pylab [GUINAME] | |
|
34 | ||
|
35 | This function lets you activate pylab (matplotlib, numpy and | |
|
36 | interactive support) at any point during an IPython session. | |
|
37 | ||
|
38 | 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. | |
|
40 | ||
|
41 | If you are using the inline matplotlib backend for embedded figures, | |
|
42 | you can adjust its behavior via the %config magic:: | |
|
43 | ||
|
44 | # enable SVG figures, necessary for SVG+XHTML export in the qtconsole | |
|
45 | In [1]: %config InlineBackend.figure_format = 'svg' | |
|
46 | ||
|
47 | # change the behavior of closing all figures at the end of each | |
|
48 | # execution (cell), or allowing reuse of active figures across | |
|
49 | # cells: | |
|
50 | In [2]: %config InlineBackend.close_figures = False | |
|
51 | ||
|
52 | Parameters | |
|
53 | ---------- | |
|
54 | guiname : optional | |
|
55 | One of the valid arguments to the %gui magic ('qt', 'wx', 'gtk', | |
|
56 | 'osx' or 'tk'). If given, the corresponding Matplotlib backend is | |
|
57 | used, otherwise matplotlib's default (which you can override in your | |
|
58 | matplotlib config file) is used. | |
|
59 | ||
|
60 | Examples | |
|
61 | -------- | |
|
62 | In this case, where the MPL default is TkAgg:: | |
|
63 | ||
|
64 | In [2]: %pylab | |
|
65 | ||
|
66 | Welcome to pylab, a matplotlib-based Python environment. | |
|
67 | Backend in use: TkAgg | |
|
68 | For more information, type 'help(pylab)'. | |
|
69 | ||
|
70 | But you can explicitly request a different backend:: | |
|
71 | ||
|
72 | In [3]: %pylab qt | |
|
73 | ||
|
74 | Welcome to pylab, a matplotlib-based Python environment. | |
|
75 | Backend in use: Qt4Agg | |
|
76 | For more information, type 'help(pylab)'. | |
|
77 | """ | |
|
78 | ||
|
79 | if Application.initialized(): | |
|
80 | app = Application.instance() | |
|
81 | try: | |
|
82 | import_all_status = app.pylab_import_all | |
|
83 | except AttributeError: | |
|
84 | import_all_status = True | |
|
85 | else: | |
|
86 | import_all_status = True | |
|
87 | ||
|
88 | self.shell.enable_pylab(parameter_s, import_all=import_all_status) |
@@ -2008,7 +2008,7 b' class InteractiveShell(SingletonConfigurable):' | |||
|
2008 | 2008 | self.register_magics(m.AutoMagics, m.BasicMagics, m.CodeMagics, |
|
2009 | 2009 | m.ConfigMagics, mf.DeprecatedMagics, m.ExecutionMagics, |
|
2010 | 2010 | m.ExtensionMagics, m.HistoryMagics, m.LoggingMagics, |
|
2011 |
m.NamespaceMagics, m.OSMagics, m |
|
|
2011 | m.NamespaceMagics, m.OSMagics, m.PylabMagics ) | |
|
2012 | 2012 | |
|
2013 | 2013 | # FIXME: Move the color initialization to the DisplayHook, which |
|
2014 | 2014 | # should be split into a prompt manager and displayhook. We probably |
@@ -15,80 +15,12 b'' | |||
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | # Our own packages |
|
18 | from IPython.config.application import Application | |
|
19 | 18 | from IPython.core.magic import Magics, register_magics, line_magic |
|
20 | from IPython.testing.skipdoctest import skip_doctest | |
|
21 | 19 | |
|
22 | 20 | #----------------------------------------------------------------------------- |
|
23 | 21 | # Magic implementation classes |
|
24 | 22 | #----------------------------------------------------------------------------- |
|
25 | 23 | |
|
26 | @register_magics | |
|
27 | class PylabMagics(Magics): | |
|
28 | """Magics related to matplotlib's pylab support""" | |
|
29 | ||
|
30 | @skip_doctest | |
|
31 | @line_magic | |
|
32 | def pylab(self, parameter_s=''): | |
|
33 | """Load numpy and matplotlib to work interactively. | |
|
34 | ||
|
35 | %pylab [GUINAME] | |
|
36 | ||
|
37 | This function lets you activate pylab (matplotlib, numpy and | |
|
38 | interactive support) at any point during an IPython session. | |
|
39 | ||
|
40 | It will import at the top level numpy as np, pyplot as plt, matplotlib, | |
|
41 | pylab and mlab, as well as all names from numpy and pylab. | |
|
42 | ||
|
43 | If you are using the inline matplotlib backend for embedded figures, | |
|
44 | you can adjust its behavior via the %config magic:: | |
|
45 | ||
|
46 | # enable SVG figures, necessary for SVG+XHTML export in the qtconsole | |
|
47 | In [1]: %config InlineBackend.figure_format = 'svg' | |
|
48 | ||
|
49 | # change the behavior of closing all figures at the end of each | |
|
50 | # execution (cell), or allowing reuse of active figures across | |
|
51 | # cells: | |
|
52 | In [2]: %config InlineBackend.close_figures = False | |
|
53 | ||
|
54 | Parameters | |
|
55 | ---------- | |
|
56 | guiname : optional | |
|
57 | One of the valid arguments to the %gui magic ('qt', 'wx', 'gtk', | |
|
58 | 'osx' or 'tk'). If given, the corresponding Matplotlib backend is | |
|
59 | used, otherwise matplotlib's default (which you can override in your | |
|
60 | matplotlib config file) is used. | |
|
61 | ||
|
62 | Examples | |
|
63 | -------- | |
|
64 | In this case, where the MPL default is TkAgg:: | |
|
65 | ||
|
66 | In [2]: %pylab | |
|
67 | ||
|
68 | Welcome to pylab, a matplotlib-based Python environment. | |
|
69 | Backend in use: TkAgg | |
|
70 | For more information, type 'help(pylab)'. | |
|
71 | ||
|
72 | But you can explicitly request a different backend:: | |
|
73 | ||
|
74 | In [3]: %pylab qt | |
|
75 | ||
|
76 | Welcome to pylab, a matplotlib-based Python environment. | |
|
77 | Backend in use: Qt4Agg | |
|
78 | For more information, type 'help(pylab)'. | |
|
79 | """ | |
|
80 | ||
|
81 | if Application.initialized(): | |
|
82 | app = Application.instance() | |
|
83 | try: | |
|
84 | import_all_status = app.pylab_import_all | |
|
85 | except AttributeError: | |
|
86 | import_all_status = True | |
|
87 | else: | |
|
88 | import_all_status = True | |
|
89 | ||
|
90 | self.shell.enable_pylab(parameter_s, import_all=import_all_status) | |
|
91 | ||
|
92 | 24 | |
|
93 | 25 | @register_magics |
|
94 | 26 | class DeprecatedMagics(Magics): |
@@ -23,6 +23,7 b' from .history import HistoryMagics' | |||
|
23 | 23 | from .logging import LoggingMagics |
|
24 | 24 | from .namespace import NamespaceMagics |
|
25 | 25 | from .osm import OSMagics |
|
26 | from .pylab import PylabMagics | |
|
26 | 27 | |
|
27 | 28 | #----------------------------------------------------------------------------- |
|
28 | 29 | # Magic implementation classes |
General Comments 0
You need to be logged in to leave comments.
Login now