Line Plots


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

In [2]:
x = np.arange(-np.pi,np.pi,0.001)
plt.plot(x,np.sin(x))


Out[2]:
[<matplotlib.lines.Line2D at 0x7f6ae47d1810>]

Add a title


In [3]:
x = np.arange(-np.pi,np.pi,0.001)
plt.plot(x,np.sin(x))
plt.title('y = sin(x)')


Out[3]:
<matplotlib.text.Text at 0x7f6ae46a5f90>

In [4]:
x = np.arange(-np.pi,np.pi,0.001)
plt.plot(x,np.sin(x))
plt.title(r'$y = \sin(x)$')


Out[4]:
<matplotlib.text.Text at 0x7f6ae45fe810>

Add x,y axis


In [5]:
x = np.arange(-np.pi,np.pi,0.001)
plt.plot(x,np.sin(x))
plt.title('y = sin(x)')
plt.xlabel('x (radians)')
plt.ylabel('y')


Out[5]:
<matplotlib.text.Text at 0x7f6ae43ab450>

Multiple plots


In [6]:
x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)

y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)

plt.subplot(2, 1, 1)
plt.plot(x1, y1, 'o-')
plt.title('A tale of 2 subplots')
plt.ylabel('Damped oscillation')

plt.subplot(2, 1, 2)
plt.plot(x2, y2, '.-')
plt.xlabel('time (s)')
plt.ylabel('Undamped')


Out[6]:
<matplotlib.text.Text at 0x7f6ae428c3d0>

More plots demo from the original site

http://matplotlib.org/gallery.html#


In [ ]: