Numpy+Matplotlib数据可视化Demo展示

1.正弦曲线函数图

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5, 5, 256)
y = np.sin(3*x)

plt.plot(x, y, 'r--')
plt.show()

Numpy+Matplotlib数据可视化Demo展示_第1张图片

2.正态分布密度函数图

import numpy as np
import pylab

np.random.seed(1234)

n = 10000
randNorm = np.random.normal(size=n)
counts, bins, path = pylab.hist(randNorm, bins=100, density=True, color='deeppink')
sigma = 1
mu = 0

norm_dist = (1/np.sqrt(2*sigma*np.pi))*np.exp(-((bins-mu)**2)/2)

pylab.plot(bins, norm_dist, color='red')

pylab.show()

Numpy+Matplotlib数据可视化Demo展示_第2张图片

3.二项分布猜硬币输赢走势图

import numpy as np
import pylab as pl

np.random.seed(1234)

binomial = np.random.binomial(9, 0.5, 10000)
money = np.zeros(10000)
money[0] = 1000

for i in range(1, 10000):
    if binomial[i] < 5:
        money[i] = money[i-1]-8
    else:
        money[i] = money[i-1]+8

pl.plot(np.arange(10000), money)

pl.show()

Numpy+Matplotlib数据可视化Demo展示_第3张图片

4.醉汉随机游走位置分布图

import numpy as np
import pylab as pl

np.random.seed(1234)

position = 0
walk = []
steps = 10000

for i in range(steps):
    step = 1 if np.random.randint(0, 2) else -1
    position += step
    walk.append(position)

pl.plot(np.arange(10000), walk)

pl.show()

Numpy+Matplotlib数据可视化Demo展示_第4张图片

你可能感兴趣的:(#,Python-Numpy,#)