如何使用matploatlib进行多个散点图

时间:2016-02-02 18:37:03

标签: python numpy pandas matplotlib

我有一些像

这样的数据
[[  0.00000000e+00   1.38680000e+04   3.04805000e+05   2.01955000e+05
4.17500000e+06]
 [  0.00000000e+00   3.48600000e+03   0.00000000e+00   0.00000000e+00
0.00000000e+00]
 [  0.00000000e+00   5.63010000e+04   0.00000000e+00   4.77000000e+02
0.00000000e+00]
[  0.00000000e+00   1.12000000e+04   1.58605500e+06   2.67102000e+05
1.20000000e+06]
[  0.00000000e+00   1.29142000e+05   0.00000000e+00   2.39671000e+05
4.00000000e+05]]
带标签的

[['poi', 'expenses', 'long_term_incentive', 'salary', 'bonus']]

如果我想获得像poi这样的散点图和其他类似的散点图 - 就像矩阵图一样 - 我怎么能这样做?我试图找到任何异常值。还有其他更好的方法吗?

1 个答案:

答案 0 :(得分:0)

You are a Udacity Machine Learning student?

Something like this might be useful for you:

import numpy as np
import matplotlib.pyplot as plt

labels = ['output','varA','varB','varC']

data = np.array([[4,5,6,2,5],
                [3,6,4,6,3],
                [12,3,5,3,2],
                [4,1,1,44, 7]])

colors = ["r", "g", "b", "k"] # make sure you have enough colors to match 
                              # the number of variables
for i in range(1, len(data)):
    plt.scatter(data[1], data[i], c=colors[i-1], s=100, alpha=0.7, label=labels[i])
plt.legend()
plt.show()

Hope that helps.

Ronny