matplotlib 练习题

matplotlib 练习题.

11.1:

matplotlib 练习题_第1张图片


代码:


#! usr/bin/python
# -*- coding: UTF-8 -*-
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2, 1000)
y = np.power(np.sin(x - 2) , 2) * np.power(np.e, np.power(x, 2) * -1)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.title(r"$sin^2(x-2)e^{-x^2}$")
plt.show()

运行结果:

matplotlib 练习题_第2张图片


11.2:matplotlib 练习题_第3张图片


代码:

#! usr/bin/python
# -*- coding: UTF-8 -*-
import matplotlib.pyplot as plt
import numpy as np

X = np.random.randn(20,10)
b = np.random.randn(10,1)
z = np.random.randn(20,1)

y = np.dot(X, b)+z

est = np.dot(np.dot(np.linalg.inv(np.dot(X.T, X)), X.T), y)

plt.plot(b, 'r^', est, 'bo')
plt.legend(['True', 'Estimalte'])
plt.show()

运行结果:

matplotlib 练习题_第4张图片


11.3:



代码:

#! usr/bin/python
# -*- coding: UTF-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as st

vals = np.random.randn(10000)

x = np.linspace(-4, 4, 1000)
y = st.gaussian_kde(vals).pdf(x)

plt.hist(vals, 25, normed = True, edgecolor = 'black')
plt.plot(x, y)
plt.show()

运行结果:

matplotlib 练习题_第5张图片


你可能感兴趣的:(matplotlib 练习题)