Tuesday, September 27, 2016

Python: Matplotlib: Histogram Example

Noteworthy:

# "Draw random samples from a normal (Gaussian) distribution."
# 正規分布(ガウス分布)からランダムにサンプルして線を描く。
numpy.random.normal(loc=0.0, scale=1.0, size=None)

# "Plot a histogram"
# ヒストグラムをプロット(描写)する。
matplotlib.pyplot.hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, color=None, label=None, stacked=False, hold=None, data=None, **kwargs)


Command:

$ cat testhistogram.py


Result:

#!/usr/local/bin/python

import matplotlib.pyplot as plt
from numpy.random import normal,rand
x = normal(size=200)
plt.hist(x,bins=30)
plt.show()


Command:

$ python testhistogram.py


Graphical output: