Prev: - | Next: Basic plotting with 'plot'

- I copy from from the matplotlib homepage:

**matplotlib** is a python 2D **plotting library** which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms

- Thus, matplotlib is the first -and possibly the only- plotting package you will ever need to develop high quality scientific plots and figures presenting your data analysis outcomes

**pyplot**is a module within the matplotlib package that provides a convenient interface to the matplotlib plotting classes and methods.- pyplot is very similar to Matlab
^{(TM)}, thus it will be easy to learn for those familiar with Matlab plotting commands and arguments.

- pyplot is better to be imported in Python scripts with its own namespace that usually is the following:

In [ ]:

```
import matplotlib.pyplot as plt
```

- Creating plots with matplotlib.pyplot can be easily accomplished in just few lines of code:

In [1]:

```
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2*np.pi, 100);
y = np.sin(x)
plt.plot(x, y)
plt.show()
```

- A new window with your plot is now open. Check it!

- Most probably you want the plot to appear right after your IPython script (('inline').
- To achieve this insert the jupyter magic command '
'. We apply this in all examples throughout the matplotlib section*%matplotlib inline*

In [2]:

```
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.linspace(0, 2*np.pi, 100);
y = np.sin(x)
plt.plot(x, y)
# No need to include 'plt.show()' command now
```

Out[2]:

. Free learning material

. See full copyright and disclaimer notice