scatterplotmatrix: 通过散点图矩阵可视化数据集

一个在 matplotlib 中创建散点图矩阵的函数

from mlxtend.plotting import scatterplotmatrix

概述

一个用于创建散点图矩阵的 matplotlib 便捷函数。

参考文献

  • -

示例 1 - 简单散点图矩阵

import matplotlib.pyplot as plt
from mlxtend.data import iris_data
from mlxtend.plotting import scatterplotmatrix


X, y = iris_data()
scatterplotmatrix(X, figsize=(10, 8))
plt.tight_layout()
plt.show()

png

示例 2 - 具有多个类别的散点图矩阵

names = ['sepal length [cm]', 'sepal width [cm]',
         'petal length [cm]', 'petal width [cm]']

fig, axes = scatterplotmatrix(X[y==0], figsize=(10, 8), alpha=0.5)
fig, axes = scatterplotmatrix(X[y==1], fig_axes=(fig, axes), alpha=0.5)
fig, axes = scatterplotmatrix(X[y==2], fig_axes=(fig, axes), alpha=0.5, names=names)

plt.tight_layout()
plt.show()

png

API

scatterplotmatrix(X, fig_axes=None, names=None, figsize=(8, 8), alpha=1.0, kwargs)

散点图矩阵的下三角形部分

参数

  • X : 数组型对象, 形状={样本数, 特征数}

    设计矩阵,包含具有多个探索性变量(特征)的数据实例(样本)。

  • fix_axes : 元组 (默认值: None)

    一个 (fig, axes) 元组,其中 fig 是一个图对象,axes 是通过 matplotlib 创建的 axes 对象,例如通过调用 pyplot 的 subplot 函数 fig, axes = plt.subplots(...) 创建。

  • names : 列表 (默认值: None)

    字符串名称列表,其元素数量应与 X 中的特征(列)数量相同。

  • figsize : 元组 (默认值: (8, 8))

    子图网格的高度和宽度。如果 fig_axes 非 None 则忽略此参数。

  • alpha : 浮点数 (默认值: 1.0)

    散点图和对角线直方图的透明度。

  • **kwargs : kwargs

    散点图的关键字参数。

返回值

  • fix_axes : 元组

    一个 (fig, axes) 元组,其中 fig 是一个图对象,axes 是通过 matplotlib 创建的 axes 对象,例如通过调用 pyplot 的 subplot 函数 fig, axes = plt.subplots(...) 创建。