The scatter graph works fine, but the second graph doesn't show. There's no error message or anything. Can anyone help, please. Here's the code.
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(xMat[:,1].flatten().A[0], yMat.T[:,0].flatten().A[0])
plt.show()
xCopy =xMat.copy()
xCopy.sort(0) #x ascending 排列
yHat = xCopy * ws #计算yHat
ax.plot(xCopy[:,1], yHat)
plt.show()
Try this:
import matplotlib.pyplot as plt
plt.figure(1)
plt.subplot(211)
plt.scatter(xMat[:,1].flatten().A[0], yMat.T[:,0].flatten().A[0])
xCopy =xMat.copy()
xCopy.sort(0) #x ascending 排列
yHat = xCopy * ws #计算yHat
plt.subplot(212)
plt.plot(xCopy[:,1], yHat)
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.