#coding =utf8 Import matplotlib.pyplot as PLT import NumPy as NP #创建数组: x, y1, y2, Y3, x4, Y4 x = Np.array ([10, 8, 13, 9, 11, 1 4, 6, 4, 7, 5]) y1 = Np.array ([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]) y2 = Np.array ([9.14 , 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74]) y3 = Np.array ([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5 (8.15, 6.42, 5.73]) x4 = Np.array ([8, 9, 8,10, 8, 6, 8, 3.8, 8,4.8]) Y4 = Np.array ([6.8, 5.6, 7.1, 8.84, 8.7, 7.04 , 5.5, 1.50, 5.6, 7.9, 6.88]) def fit (x): Return 1+ 4 * X/5 #创建xfit数组, the array contains two elements: X's maximum and minimum xfit = Np.array ([Np.min (x ), Np.max (x)]) #创建子图 Plt.subplot (221) #在第一张子图上绘制两个图形 #x, y1 scatter plot, black squares #xfit, Fit (xfit) Red solid line, line width 2 plt.plot (x, y1, ' ks ', Xfit,
Fit (Xfit), ' R ', lw=2 #设置x轴范围: 2 to #设置y轴范围: 2 to Plt.axis ([2, 2, M]) #plt. GCA (): Gets the current child graph #plt. SETP (): Sets the properties of an icon instance. #设置子图的xticklabels为空 #yticks显示为: 4, 8, 12,,xticks display: 0, 10, PLT.SETP (PLT.GCA (), xticklabels=[), yticks= (4, 8,), Xticks = (0, pyplot) #matplotlib.. text (x, y, S, Fontdict=none, Withdash=false, **kwargs) # The first argument is the x-axis coordinate # The second parameter is the Y coordinate # The third argument is the content to be explicit #fontsize设置显示字体大小 p Lt.text (3,, ' I ', fontsize=20) #创建第二个子图 Plt.subplot (222) #绘制两个图形 #x, y2 scatter plot, black squares #xfit, Fit (xfit) Red solid line, line width to 2 plt.plot (x, y
2, ' KS ', Xfit, Fit (xfit), ' R ', lw=2 ' Plt.axis ([2, 2,]) #plt. GCA (): Gets the current child graph #plt. SETP (): Sets the properties of an icon instance. #设置子图的xticklabels, Yticklabels is empty #yticks显示为: 4, 8, 12,,xticks display: 0, 10, PLT.SETP (PLT.GCA (), xticks= (0, a), Xticklab Els=[], yticks= (4, 8,), yticklabels=[], Plt.text (3,, ' II ', fontsize=20) plt.subplot (223) plt.plot (x, Y3, ' KS ', Xfit, Fit (xfit), ' R ', lw=2 ' Plt.axis ([2, 2,]) Plt.setp (PLT.GCA (), yticks= (4, 8,), xticks= (0, m)) PL T.text (3,, ' III ', fontsize=20) Plt.subplot (224) Xfit = Np.array ([Np.min (x4), Np.max (x4)]) Plt.plot (x4, Y4, ' ks ', Xfit , Fit (Xfit), ' R ', lw=2 Plt.axis ([2, 2,]) Plt.setp (PLT.GCA (), yticklabels=[], yticks= (4, 8,), xticks= (0, 10, 20 ) Plt.text (3,, ' IV ', fontsize=20) # VerificationThe Data pairs = (x, y1), (x, y2), (x, Y3), (x4, Y4) #corrcoef函数 #计算两组数的相关系数 #返回结果为矩阵, the data in the J column of line I is the correlation coefficient of group I and number J. Diagonal 1 for x, y in Pairs:print ' mean=%1.2f, std=%1.2f, r=%1.2f '% (Np.mean (y), np.std (y), Np.corrcoef (x, y) [0][1]) #显示
Draw Image Plt.show ()