| title | description | ms.custom | ms.date | ms.technology | dev_langs | ms.topic | author | ms.author | manager | ms.workload | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
IPython REPL (interactive window) |
Using the Visual Studio interactive window in IPython mode for a user-friendly interactive development environment with Interactive Parallel Computing features. |
07/13/2017 |
|
|
conceptual |
kraigb |
kraigb |
douge |
|
The Visual Studio interactive window in IPython mode is an advanced yet user-friendly interactive development environment that has Interactive Parallel Computing features. This article walks through using IPython in the Visual Studio interactive window, in which all of the regular interactive window features are also available.
For this walkthrough you should have the Anaconda environment installed, which includes IPython and the necessary libraries.
Note
IronPython does not support IPython, despite the fact that you can select it on the Interactive Options form. FOr more information see the feature request.
-
Open Visual Studio, switch to the Python Environments window (View > Other Windows > Python Environments), and select the Python environment that appeared when you started IPython.
-
Look at the Packages (or pip) tab and ensure that
IPythonandmatplotlibare listed. If not, install them here. -
Select the Overview tab and select Use IPython interactive mode. (In Visual Studio 2015, select Configure interactive options to open the Options dialog, then set Interactive Mode to IPython, and select OK).
-
Select Open interactive window to bring up the interactive window in IPython mode. You may need to reset the window if you have just changed the interactive mode; you might also need to press Enter if only a >>> prompt appears.
-
Enter the following code:
x = linspace(0, 5, 10)
y = x ** 2
plot(x, y, 'r', x, x ** 3, 'g', x, x ** 4, 'b')-
After entering the last line, you should see an inline graph (which you can resize by dragging on the lower right-hand corner) if desired.
-
Instead of typing in the REPL, you can instead write code in the editor, select it, right-click, and select the Send to interactive command (or press Ctrl-Enter). Try pasting the code below into a new file in the editor, selecting it with Ctrl-A, then sending to the interactive window. (Note that Visual Studio sends the code as one unit to avoid giving you intermediate or partial graphs. Also note that if you don't have a Python project open with a different environment selected, Visual Studio opens an interactive window for whatever environment is selected as your default in the Python Environments window.)
from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]): xs = np.arange(20) ys = np.random.rand(20) # You can provide either a single color or an array. To demonstrate this, # the first bar of each set is colored cyan. cs = [c] * len(xs) cs[0] = 'c' ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.show()
-
To see the graphs outside of the interactive window, run the code instead using the Debug > Start without Debugging command.
IPython has many other useful features such as escaping to the system shell, variable substitution, capturing output, etc. Refer to the IPython documentation for more.
-
To use Jupyter easily and without installation, try the free Azure Notebooks hosted service that lets you keep and share your notebooks with others.
-
You can also run Jupyter (formerly known as IPython) on your own Windows or Linux virtual machine on Azure. For details, see Creating an Azure VM. installing Jupyter, and running Jupyter Notebook on Azure.


