今天在写python画散点图做相关性分析时遇到’module ‘pandas’ has no attribute ‘scatter_matrix’'这个问题
原代码:
data=pd.DataFrame(np.random.randn(200,4)*100,columns=['A','B','C','D'])
pd.scatter_matrix(data,figsize=(8,8),
c='k',
marker='+',
diagonal='hist',
alpha=0.8,
range_padding=0.1)
输出结果:
AttributeError: module ‘pandas’ has no attribute ‘scatter_matrix’
后来去查了pandas文档,发现现在的pandas的scatter_matrix用法已经发生变化了,在使用时需要加上plotting,即:pandas.plotting.scatter_matrix
修改后:
data=pd.DataFrame(np.random.randn(200,4)*100,columns=['A','B','C','D'])
pd.plotting.scatter_matrix(data,figsize=(8,8),
c='k',
marker='+',
diagonal='hist',
alpha=0.8,
range_padding=0.1)
输出结果: