scatter_hist: 创建散点直方图绘图

一个快速生成散点直方图的函数。

从mlxtend.plotting导入散点直方图

概述

参考文献

示例 1 - 来自 Pandas DataFrame 的散点图和直方图

from mlxtend.data import iris_data
from mlxtend.plotting import scatter_hist
import pandas as pd


X, y = iris_data()
df = pd.DataFrame(X)
df.columns = ['sepal length [cm]', 'sepal width [cm]', 'petal length [cm]', 'petal width [cm]']
df.head(5)

sepal length [cm] sepal width [cm] petal length [cm] petal width [cm]
0 5.1 3.5 1.4 0.2
1 4.9 3.0 1.4 0.2
2 4.7 3.2 1.3 0.2
3 4.6 3.1 1.5 0.2
4 5.0 3.6 1.4 0.2
import matplotlib.pyplot as plt
from mlxtend.plotting import scatter_hist


fig = scatter_hist(df["sepal length [cm]"], df["sepal width [cm]"])

png

示例 2 - 来自 NumPy 数组的类别散点图

from mlxtend.data import iris_data
from mlxtend.plotting import scatter_hist
import pandas as pd


X, y = iris_data()
X[:5]

array([[5.1, 3.5, 1.4, 0.2],
       [4.9, 3. , 1.4, 0.2],
       [4.7, 3.2, 1.3, 0.2],
       [4.6, 3.1, 1.5, 0.2],
       [5. , 3.6, 1.4, 0.2]])
fig = scatter_hist(X[:, 0], X[:, 1])

png

API

scatter_hist(x, y, xlabel=None, ylabel=None, figsize=(5, 5))

Scatter plot and individual feature histograms along axes.

Parameters

Returns