matplotlib 这个库很重要!
import numpy as np
import matplotlib as plt
任务1:以画贝叶斯分类器的后验概率为例:
xnew = np.linspace(-5, 5, 300) # 300 represents number of points to make between min and T
ynew = np.array([postProb(x, W1, W2) for x in xnew]) #postProb() is a function returns the posterior probability of certain x
znew = np.array([postProb(x, W2, W1) for x in xnew])
plt.plot(xnew, ynew, 'r')
plt.plot(xnew, znew, 'b') # one line red and one line blue
plt.show()
改进1:设置线宽
plt.plot(xnew, y1, linewidth = 0.5)
改进2:设置坐标轴范围
plt.axis([-6, 6, 0, 0.4])
改进3:设置颜色添加图例
plt.plot(xnew, y2, label = 'class 2', linewidth = 0.5) # add label
plt.legend()