Wednesday, September 28, 2016

Python: Matplotlib: Sine Function Example

Noteworthy:

numpy.sin()
numpy.pi


Command:

$ cat Downloads/simple_plot.py


Result:

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
plt.plot(t, s)

plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.savefig("test.png")
plt.show()


Command:

$ python Downloads/simple_plot.py


Graphical output: