1、
代码如下:
import matplotlib.pyplot as plt
from math import *
input_values = [i/10000 for i in range(1, 20000)]
y = [pow(sin(x-2), 2)*pow(e, -pow(x, 2)) for x in input_values]
plt.plot(input_values, y, linewidth=5)
plt.title("function", fontsize=24)
plt.xlabel("Value", fontsize=14)
plt.ylabel("f_value", fontsize=14)
plt.tick_params(axis="both", labelsize=14)
plt.show()
运行结果:
2、
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import leastsq
X = np.random.randint(0,10,(20,10))
b = (np.random.randint(-5,5,(1,10))).T
z = np.random.randn(20,1)
y = np.dot(X,b)+z
est_b = (np.linalg.lstsq(X, y, rcond=None)[0]).T
x =range(0,10)
plt.scatter(x, b, c='b', marker='o', label='true parameters')
plt.scatter(x, est_b, c='r', marker='x', label='estimated parameters')
plt.legend()
plt.xlabel('index')
plt.ylabel('value')
plt.show()
运行结果:
3、
代码如下:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
data = np.random.randn(10000)
n, bins, patches = plt.hist(data, 25, normed=True, facecolor='r')
y = mlab.normpdf(bins, 0, 1)
plt.plot(bins, y, 'b')
plt.title('Normal Distribution')
plt.show()
运行结果: