散点图矩阵

0 投票
1 回答
2573 浏览
提问于 2025-06-18 04:05

我想为我的矩阵做一个散点图。

我找到了一个叫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 个回答

4

你只需要这样写 hue='species'

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

输出结果:

在这里输入图片描述

撰写回答