Show More
@@ -78,9 +78,9 b' IPython, opening IPython as your Python shell via ``C-c !``, etc.' | |||||
78 |
|
78 | |||
79 | You can customize the arguments passed to the IPython instance at startup by |
|
79 | You can customize the arguments passed to the IPython instance at startup by | |
80 | setting the ``py-python-command-args`` variable. For example, to start always |
|
80 | setting the ``py-python-command-args`` variable. For example, to start always | |
81 |
|
|
81 | with ``matplotlib`` integration and hardcoded light-background colors, you can use:: | |
82 |
|
82 | |||
83 |
(setq py-python-command-args '("- |
|
83 | (setq py-python-command-args '("--matplotlib" "--colors" "LightBG")) | |
84 |
|
84 | |||
85 | If you happen to get garbage instead of colored prompts as described in |
|
85 | If you happen to get garbage instead of colored prompts as described in | |
86 | the previous section, you may need to set also in your :file:`.emacs` file:: |
|
86 | the previous section, you may need to set also in your :file:`.emacs` file:: |
@@ -484,9 +484,9 b' For instance:' | |||||
484 | # is equivalent to |
|
484 | # is equivalent to | |
485 | $> ipcontroller --Application.log_level=DEBUG |
|
485 | $> ipcontroller --Application.log_level=DEBUG | |
486 | # and |
|
486 | # and | |
487 |
$> ipython -- |
|
487 | $> ipython --matploitlib | |
488 | # is equivalent to |
|
488 | # is equivalent to | |
489 |
$> ipython -- |
|
489 | $> ipython --matplotlib auto | |
490 | # or |
|
490 | # or | |
491 | $> ipython --no-banner |
|
491 | $> ipython --no-banner | |
492 | # is equivalent to |
|
492 | # is equivalent to | |
@@ -502,14 +502,14 b' Some IPython applications have **subcommands**. Subcommands are modeled after' | |||||
502 |
|
502 | |||
503 | .. code-block:: bash |
|
503 | .. code-block:: bash | |
504 |
|
504 | |||
505 |
$> ipython qtconsole --profile |
|
505 | $> ipython qtconsole --profile myprofile | |
506 |
|
506 | |||
507 | and :command:`ipcluster` is simply a wrapper for its various subcommands (start, |
|
507 | and :command:`ipcluster` is simply a wrapper for its various subcommands (start, | |
508 | stop, engines). |
|
508 | stop, engines). | |
509 |
|
509 | |||
510 | .. code-block:: bash |
|
510 | .. code-block:: bash | |
511 |
|
511 | |||
512 |
$> ipcluster start --profile=myprofile - |
|
512 | $> ipcluster start --profile=myprofile -n 4 | |
513 |
|
513 | |||
514 |
|
514 | |||
515 | To see a list of the available aliases, flags, and subcommands for an IPython application, simply pass ``-h`` or ``--help``. And to see the full list of configurable options (*very* long), pass ``--help-all``. |
|
515 | To see a list of the available aliases, flags, and subcommands for an IPython application, simply pass ``-h`` or ``--help``. And to see the full list of configurable options (*very* long), pass ``--help-all``. |
@@ -48,19 +48,19 b' for playing with examples from documentation, such as matplotlib.' | |||||
48 |
|
48 | |||
49 | In [7]: from mpl_toolkits.mplot3d import axes3d |
|
49 | In [7]: from mpl_toolkits.mplot3d import axes3d | |
50 | ...: import matplotlib.pyplot as plt |
|
50 | ...: import matplotlib.pyplot as plt | |
51 |
...: |
|
51 | ...: | |
52 | ...: fig = plt.figure() |
|
52 | ...: fig = plt.figure() | |
53 | ...: ax = fig.add_subplot(111, projection='3d') |
|
53 | ...: ax = fig.add_subplot(111, projection='3d') | |
54 | ...: X, Y, Z = axes3d.get_test_data(0.05) |
|
54 | ...: X, Y, Z = axes3d.get_test_data(0.05) | |
55 | ...: cset = ax.contour(X, Y, Z) |
|
55 | ...: cset = ax.contour(X, Y, Z) | |
56 | ...: ax.clabel(cset, fontsize=9, inline=1) |
|
56 | ...: ax.clabel(cset, fontsize=9, inline=1) | |
57 |
...: |
|
57 | ...: | |
58 | ...: plt.show() |
|
58 | ...: plt.show() | |
59 |
|
59 | |||
60 | Pylab |
|
60 | Inline Matplotlib | |
61 | ===== |
|
61 | ================= | |
62 |
|
62 | |||
63 |
One of the most exciting features of the |
|
63 | One of the most exciting features of the QtConsole is embedded matplotlib | |
64 | figures. You can use any standard matplotlib GUI backend |
|
64 | figures. You can use any standard matplotlib GUI backend | |
65 | to draw the figures, and since there is now a two-process model, there is no |
|
65 | to draw the figures, and since there is now a two-process model, there is no | |
66 | longer a conflict between user input and the drawing eventloop. |
|
66 | longer a conflict between user input and the drawing eventloop. | |
@@ -68,24 +68,27 b' longer a conflict between user input and the drawing eventloop.' | |||||
68 | .. image:: figs/besselj.png |
|
68 | .. image:: figs/besselj.png | |
69 | :width: 519px |
|
69 | :width: 519px | |
70 |
|
70 | |||
71 | .. display: |
|
71 | .. _display: | |
72 |
|
72 | |||
73 | :func:`display` |
|
73 | :func:`display` | |
74 | *************** |
|
74 | *************** | |
75 |
|
75 | |||
76 | An additional function, :func:`display`, will be added to the global namespace |
|
76 | IPython provides a function :func:`display` for displaying rich representations | |
77 | if you specify the ``--pylab`` option at the command line. The IPython display |
|
77 | of objects if they are available. The IPython display | |
78 | system provides a mechanism for specifying PNG or SVG (and more) |
|
78 | system provides a mechanism for specifying PNG or SVG (and more) | |
79 |
representations of objects for GUI frontends. |
|
79 | representations of objects for GUI frontends. | |
|
80 | When you enable matplotlib integration via the ``%matplotlib`` magic, IPython registers | |||
80 | convenient PNG and SVG renderers for matplotlib figures, so you can embed them |
|
81 | convenient PNG and SVG renderers for matplotlib figures, so you can embed them | |
81 | in your document by calling :func:`display` on one or more of them. This is |
|
82 | in your document by calling :func:`display` on one or more of them. This is | |
82 | especially useful for saving_ your work. |
|
83 | especially useful for saving_ your work. | |
83 |
|
84 | |||
84 | .. sourcecode:: ipython |
|
85 | .. sourcecode:: ipython | |
85 |
|
86 | |||
86 | In [5]: plot(range(5)) # plots in the matplotlib window |
|
87 | In [4]: from IPython.display import display | |
|
88 | ||||
|
89 | In [5]: plt.plot(range(5)) # plots in the matplotlib window | |||
87 |
|
90 | |||
88 | In [6]: display(gcf()) # embeds the current figure in the qtconsole |
|
91 | In [6]: display(plt.gcf()) # embeds the current figure in the qtconsole | |
89 |
|
92 | |||
90 | In [7]: display(*getfigs()) # embeds all active figures in the qtconsole |
|
93 | In [7]: display(*getfigs()) # embeds all active figures in the qtconsole | |
91 |
|
94 | |||
@@ -94,16 +97,16 b' that specific figure:' | |||||
94 |
|
97 | |||
95 | .. sourcecode:: ipython |
|
98 | .. sourcecode:: ipython | |
96 |
|
99 | |||
97 | In [1]: f = figure() |
|
100 | In [1]: f = plt.figure() | |
98 |
|
101 | |||
99 | In [2]: plot(rand(100)) |
|
102 | In [2]: plt.plot(np.rand(100)) | |
100 | Out[2]: [<matplotlib.lines.Line2D at 0x7fc6ac03dd90>] |
|
103 | Out[2]: [<matplotlib.lines.Line2D at 0x7fc6ac03dd90>] | |
101 |
|
104 | |||
102 | In [3]: display(f) |
|
105 | In [3]: display(f) | |
103 |
|
106 | |||
104 | # Plot is shown here |
|
107 | # Plot is shown here | |
105 |
|
108 | |||
106 | In [4]: title('A title') |
|
109 | In [4]: plt.title('A title') | |
107 | Out[4]: <matplotlib.text.Text at 0x7fc6ac023450> |
|
110 | Out[4]: <matplotlib.text.Text at 0x7fc6ac023450> | |
108 |
|
111 | |||
109 | In [5]: display(f) |
|
112 | In [5]: display(f) | |
@@ -112,15 +115,16 b' that specific figure:' | |||||
112 |
|
115 | |||
113 | .. _inline: |
|
116 | .. _inline: | |
114 |
|
117 | |||
115 |
``-- |
|
118 | ``--matplotlib inline`` | |
116 | ****************** |
|
119 | *********************** | |
117 |
|
120 | |||
118 | If you want to have all of your figures embedded in your session, instead of |
|
121 | If you want to have all of your figures embedded in your session, instead of | |
119 |
calling :func:`display`, you can specify ``-- |
|
122 | calling :func:`display`, you can specify ``--matplotlib inline`` when you start the | |
120 | console, and each time you make a plot, it will show up in your document, as if |
|
123 | console, and each time you make a plot, it will show up in your document, as if | |
121 | you had called :func:`display(fig)`. |
|
124 | you had called :func:`display(fig)`. | |
122 |
|
125 | |||
123 | The inline backend can use either SVG or PNG figures (PNG being the default). |
|
126 | The inline backend can use either SVG or PNG figures (PNG being the default). | |
|
127 | It also supports the special key ``'retina'``, which is 2x PNG for high-DPI displays. | |||
124 | To switch between them, set the ``InlineBackend.figure_format`` configurable |
|
128 | To switch between them, set the ``InlineBackend.figure_format`` configurable | |
125 | in a config file, or via the ``%config`` magic: |
|
129 | in a config file, or via the ``%config`` magic: | |
126 |
|
130 | |||
@@ -140,10 +144,10 b' each cell will always create a new figure:' | |||||
140 |
|
144 | |||
141 | .. sourcecode:: ipython |
|
145 | .. sourcecode:: ipython | |
142 |
|
146 | |||
143 | In [11]: plot(range(100)) |
|
147 | In [11]: plt.plot(range(100)) | |
144 | <single-line plot> |
|
148 | <single-line plot> | |
145 |
|
149 | |||
146 | In [12]: plot([1,3,2]) |
|
150 | In [12]: plt.plot([1,3,2]) | |
147 | <another single-line plot> |
|
151 | <another single-line plot> | |
148 |
|
152 | |||
149 |
|
153 | |||
@@ -177,7 +181,7 b' Saving and Printing' | |||||
177 | =================== |
|
181 | =================== | |
178 |
|
182 | |||
179 | IPythonQt has the ability to save your current session, as either HTML or |
|
183 | IPythonQt has the ability to save your current session, as either HTML or | |
180 |
XHTML. If you have been using :func:`display` or inline_ |
|
184 | XHTML. If you have been using :func:`display` or inline_ matplotlib, your figures | |
181 | will be PNG in HTML, or inlined as SVG in XHTML. PNG images have the option to |
|
185 | will be PNG in HTML, or inlined as SVG in XHTML. PNG images have the option to | |
182 | be either in an external folder, as in many browsers' "Webpage, Complete" |
|
186 | be either in an external folder, as in many browsers' "Webpage, Complete" | |
183 | option, or inlined as well, for a larger, but more portable file. |
|
187 | option, or inlined as well, for a larger, but more portable file. | |
@@ -546,7 +550,7 b' An important part of working with the QtConsole when you are writing your own' | |||||
546 | Qt code is to remember that user code (in the kernel) is *not* in the same |
|
550 | Qt code is to remember that user code (in the kernel) is *not* in the same | |
547 | process as the frontend. This means that there is not necessarily any Qt code |
|
551 | process as the frontend. This means that there is not necessarily any Qt code | |
548 | running in the kernel, and under most normal circumstances there isn't. If, |
|
552 | running in the kernel, and under most normal circumstances there isn't. If, | |
549 |
however, you specify ``-- |
|
553 | however, you specify ``--matplotlib qt`` at the command-line, then there *will* be a | |
550 | :class:`QCoreApplication` instance running in the kernel process along with |
|
554 | :class:`QCoreApplication` instance running in the kernel process along with | |
551 | user-code. To get a reference to this application, do: |
|
555 | user-code. To get a reference to this application, do: | |
552 |
|
556 |
@@ -60,17 +60,13 b' Since engines are IPython as well, you can even run magics remotely:' | |||||
60 | In [28]: %px %pylab inline |
|
60 | In [28]: %px %pylab inline | |
61 | Parallel execution on engine(s): all |
|
61 | Parallel execution on engine(s): all | |
62 | [stdout:0] |
|
62 | [stdout:0] | |
63 | Welcome to pylab, a matplotlib-based Python environment... |
|
63 | Populating the interactive namespace from numpy and matplotlib | |
64 | For more information, type 'help(pylab)'. |
|
|||
65 | [stdout:1] |
|
64 | [stdout:1] | |
66 | Welcome to pylab, a matplotlib-based Python environment... |
|
65 | Populating the interactive namespace from numpy and matplotlib | |
67 | For more information, type 'help(pylab)'. |
|
|||
68 | [stdout:2] |
|
66 | [stdout:2] | |
69 | Welcome to pylab, a matplotlib-based Python environment... |
|
67 | Populating the interactive namespace from numpy and matplotlib | |
70 | For more information, type 'help(pylab)'. |
|
|||
71 | [stdout:3] |
|
68 | [stdout:3] | |
72 | Welcome to pylab, a matplotlib-based Python environment... |
|
69 | Populating the interactive namespace from numpy and matplotlib | |
73 | For more information, type 'help(pylab)'. |
|
|||
74 |
|
70 | |||
75 | And once in pylab mode with the inline backend, |
|
71 | And once in pylab mode with the inline backend, | |
76 | you can make plots and they will be displayed in your frontend |
|
72 | you can make plots and they will be displayed in your frontend |
@@ -5,13 +5,18 b' Parallel examples' | |||||
5 | ================= |
|
5 | ================= | |
6 |
|
6 | |||
7 | In this section we describe two more involved examples of using an IPython |
|
7 | In this section we describe two more involved examples of using an IPython | |
8 |
cluster to perform a parallel computation. |
|
8 | cluster to perform a parallel computation. We will be doing some plotting, | |
9 | IPython's "pylab" mode, which enables interactive plotting using the |
|
9 | so we start IPython with matplotlib integration by typing:: | |
10 | Matplotlib package. IPython can be started in this mode by typing:: |
|
|||
11 |
|
10 | |||
12 |
ipython -- |
|
11 | ipython --matplotlib | |
13 |
|
12 | |||
14 | at the system command line. |
|
13 | at the system command line. | |
|
14 | Or you can enable matplotlib integration at any point with: | |||
|
15 | ||||
|
16 | .. sourcecode:: ipython | |||
|
17 | ||||
|
18 | In [1]: %matplotlib | |||
|
19 | ||||
15 |
|
20 | |||
16 | 150 million digits of pi |
|
21 | 150 million digits of pi | |
17 | ======================== |
|
22 | ======================== | |
@@ -62,8 +67,6 b' SymPy:' | |||||
62 |
|
67 | |||
63 | In [11]: digits = (d for d in str(pi)[2:]) # create a sequence of digits |
|
68 | In [11]: digits = (d for d in str(pi)[2:]) # create a sequence of digits | |
64 |
|
69 | |||
65 | In [12]: run pidigits.py # load one_digit_freqs/plot_one_digit_freqs |
|
|||
66 |
|
||||
67 | In [13]: freqs = one_digit_freqs(digits) |
|
70 | In [13]: freqs = one_digit_freqs(digits) | |
68 |
|
71 | |||
69 | In [14]: plot_one_digit_freqs(freqs) |
|
72 | In [14]: plot_one_digit_freqs(freqs) | |
@@ -111,7 +114,7 b' using IPython by following these steps:' | |||||
111 | 1. Use :command:`ipcluster` to start 15 engines. We used 16 cores of an SGE linux |
|
114 | 1. Use :command:`ipcluster` to start 15 engines. We used 16 cores of an SGE linux | |
112 | cluster (1 controller + 15 engines). |
|
115 | cluster (1 controller + 15 engines). | |
113 | 2. With the file :file:`parallelpi.py` in your current working directory, open |
|
116 | 2. With the file :file:`parallelpi.py` in your current working directory, open | |
114 |
up IPython |
|
117 | up IPython, enable matplotlib, and type ``run parallelpi.py``. This will download | |
115 | the pi files via ftp the first time you run it, if they are not |
|
118 | the pi files via ftp the first time you run it, if they are not | |
116 | present in the Engines' working directory. |
|
119 | present in the Engines' working directory. | |
117 |
|
120 |
General Comments 0
You need to be logged in to leave comments.
Login now