散点图矩阵:通过散点图矩阵可视化数据集
一个用于在matplotlib中创建散点图矩阵的函数
> 从 mlxtend.plotting 导入 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()
示例 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()
API
scatterplotmatrix(X, fig_axes=None, names=None, figsize=(8, 8), alpha=1.0, kwargs)
Lower triangular of a scatterplot matrix
Parameters
-
X
: array-like, shape={num_examples, num_features}Design matrix containing data instances (examples) with multiple exploratory variables (features).
-
fix_axes
: tuple (default: None)A
(fig, axes)
tuple, where fig is an figure object and axes is an axes object created via matplotlib, for example, by calling the pyplotsubplot
functionfig, axes = plt.subplots(...)
-
names
: list (default: None)A list of string names, which should have the same number of elements as there are features (columns) in
X
. -
figsize
: tuple (default: (8, 8))Height and width of the subplot grid. Ignored if fig_axes is not
None
. -
alpha
: float (default: 1.0)Transparency for both the scatter plots and the histograms along the diagonal.
-
**kwargs
: kwargsKeyword arguments for the scatterplots.
Returns
-
fix_axes
: tupleA
(fig, axes)
tuple, where fig is an figure object and axes is an axes object created via matplotlib, for example, by calling the pyplotsubplot
functionfig, axes = plt.subplots(...)