IPython works with the [Matplotlib](http://matplotlib.org/) plotting library, which integrates Matplotlib with IPython's display system and event loop handling.
%% Cell type:markdown id: tags:
## matplotlib mode
%% Cell type:markdown id: tags:
To make plots using Matplotlib, you must first enable IPython's matplotlib mode.
To do this, run the `%matplotlib` magic command to enable plotting in the current Notebook.
This magic takes an optional argument that specifies which Matplotlib backend should be used. Most of the time, in the Notebook, you will want to use the `inline` backend, which will embed plots inside the Notebook:
%% Cell type:code id: tags:
``` python
%matplotlibinline
```
%% Cell type:markdown id: tags:
You can also use Matplotlib GUI backends in the Notebook, such as the Qt backend (`%matplotlib qt`). This will use Matplotlib's interactive Qt UI in a floating window to the side of your browser. Of course, this only works if your browser is running on the same system as the Notebook Server. You can always call the `display` function to paste figures into the Notebook document.
%% Cell type:markdown id: tags:
## Making a simple plot
%% Cell type:markdown id: tags:
With matplotlib enabled, plotting should just work.
%% Cell type:code id: tags:
``` python
importmatplotlib.pyplotasplt
importnumpyasnp
```
%% Cell type:code id: tags:
``` python
x=np.linspace(0,3*np.pi,500)
plt.plot(x,np.sin(x**2))
plt.title('A simple chirp');
```
%% Cell type:markdown id: tags:
These images can be resized by dragging the handle in the lower right corner. Double clicking will return them to their original size.
%% Cell type:markdown id: tags:
One thing to be aware of is that by default, the `Figure` object is cleared at the end of each cell, so you will need to issue all plotting commands for a single figure in a single cell.
%% Cell type:markdown id: tags:
## Loading Matplotlib demos with %load
%% Cell type:markdown id: tags:
IPython's `%load` magic can be used to load any Matplotlib demo by its URL: