1 X1D=np.linspace(-4, 4, 9).reshape(-1,1)
2 X2D=np.c_[X1D, X1D**2]
3 y = np.array([0, 0, 1, 1, 1, 1, 1, 0, 0])
4
5 plt.figure(figsize=(11, 4)) #这个范围是怎么知道的?经验值
6 pprint(np.zeros(4))
7 plt.subplot(121)
8 plt.grid(True, which=“both”)
9 plt.axhline(y=0, color=‘k’) # 这个是什么意思,axhline,画一条水平的线,k颜色的
10 plt.plot(X1D[y0, 0], np.zeros(4), “bs”)
11 plt.plot(X1D[y1, 0], np.zeros(5), “g^”) #为什么这个zero(5)?因为y1分类的X,共有5个元素(y0的分类,X有4个元素)
12 plt.gca().get_yaxis().set_ticks([]) #gca:get currnt axes(轴),get_yaxis,获取y轴对象,set_ticks([]),去掉y轴
13 plt.xlabel(r’
x
1
x_1
x1’, fontsize=12)
14 plt.axis([-4.5, 4.5, -0.2, 0.2]) # 这个范围是怎么确定的?
15
16 #为什么是122,其他数字是否可以?代表一行,2列(两张图并排显示),当前图是第2个(靠右显示的图),如果是211和212则是竖着排列的两张图
17 plt.subplot(122)
18 plt.grid(True, which=“both”)
19 plt.axhline(y=0, color=“k”)
20 plt.axvline(x=0, color=“k”) # 在x=0处画一条垂直的线
21
22 plt.plot(X2D[y1,0], X2D[y1,1], “gs”)
23 plt.plot(X2D[y0,0], X2D[y0,1], “b^”)
24 plt.xlabel(r"
x
1
x_1
x1", fontsize=20)
25 plt.ylabel(r"
x
2
x_2
x2", fontsize=20)
26 plt.gca().get_yaxis().set_ticks([0, 4, 8, 12, 16]) # 在y轴显示刻度0,4,8…
27 plt.plot([-4.5, 4.5], [6.5,6.5], “r–”, linewidth=3)
28 plt.axis([-4.5, 4.5, -1, 17])
29
30 plt.subplots_adjust(right=1) #控制图像的位置以及间隔;调整right值之后,感觉整体图像会变大变小。
31
32 plt.show()
原谅我忘记了临时在外面弄了一个!!!