利用pandas进行相关性分析并绘制图

data=pd.read_csv('modisandobserve.txt')
xs=data['observe']
ys=data['modis']
plt.scatter(xs,ys)

def slope_intercept(x_val,y_val):
    x=np.array(x_val)
    y=np.array(y_val)
    m=(((np.mean(x)*np.mean(y))-np.mean(x*y))/((np.mean(x)*np.mean(x))-np.mean(x*x)))
    m=round(m,2)
    b=(np.mean(y)-np.mean(x)*m)
    b=round(b,2)
    return m,b
m,b=slope_intercept(xs,ys)
reg_line=[(m*x)+b for x in xs]
plt.scatter(xs,ys,edgecolors='red')
plt.xlim(0,1.6)
plt.ylim(0,1.6)
plt.xlabel('Lidar AOD')
plt.ylabel('MODIS AOD')
plt.plot(xs,reg_line)
plt.show()

你可能感兴趣的:(python学习)