Friday, March 27, 2015

Python plot sin, cos and tan, using pylab and numpy


import pylab as pl
import numpy as np

X = np.linspace(0, 2*np.pi, 360, endpoint=True)
Y = np.sin(X)
Y2 = np.cos(X)
pl.plot(X, Y)
pl.plot(X, Y2)

pl.show()

numpy and matplotlib are needed in this example.

Install for Python 2:
$ sudo apt-get install python-numpy
$ sudo apt-get install python-matplotlib

Install for Python 3:
$ sudo apt-get install python3-numpy
$ sudo apt-get install python3-matplotlib