散点图矩阵

时间:2020-05-18 20:52:02

标签: python matplotlib matrix seaborn

我想得到我所有矩阵的散点图。

我发现模块是固定的,我做了类似的事情。

import seaborn as sns

data_ = pd.read_csv('/content/drive/My Drive/Colab Notebooks/Machine Learning/iris.csv', skiprows=1, delimiter=',')
sns.pairplot(data_)

enter image description here

我想知道如何赋予它颜色,就像这张图片一样。

enter image description here

我也想知道是否有某种方法可以从Matplotlib中查看我的绘图矩阵,而无需一个接一个地创建自己的图形。非常感谢!

已更新:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2645             try:
-> 2646                 return self._engine.get_loc(key)
   2647             except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'variety'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
4 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2646                 return self._engine.get_loc(key)
   2647             except KeyError:
-> 2648                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2649         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   2650         if indexer.ndim > 1 or indexer.size > 1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'variety'

1 个答案:

答案 0 :(得分:2)

您可以执行hue='species'

sns.pairplot(data_, hue='species')

输出:

enter image description here