Tuesday, September 27, 2016

Python: Matplotlib: Line Plot Example

Noteworthy:

# "Return evenly spaced numbers over a specified interval."
# 等間隔に並べた数字を返す。
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)

# "Calculate the exponential of all elements in the input array."
# 指数の計算
numpy.exp(x[, out]) = <ufunc 'exp'>

# "Display a figure."
# フィギュアを表示する。
matplotlib.pyplot.show(*args, **kw)


Command:

$ cat testlineplot.py


Result:

#!/usr/local/bin/python

import matplotlib.pyplot as plt
import numpy as np
a = np.linspace(0,10,100)
b = np.exp(-a)
plt.plot(a,b)
plt.show()


Graphical output: