[ SKILL_DOCUMENTATION ]
# 数据可视化
本参考指南涵盖了 Vaex 的可视化功能,用于创建图表、热力图以及大规模数据集的交互式可视化。
## 概述
Vaex 通过高效的分箱和聚合,擅长可视化包含数十亿行的数据集。可视化系统直接处理大数据而无需采样,提供整个数据集的准确表示。
**核心特性:**
- 交互式可视化十亿行级别的数据集
- 无需采样 - 使用所有数据
- 自动分箱和聚合
- 与 matplotlib 集成
- Jupyter 的交互式小部件
## 基础绘图
### 一维直方图
python
import vaex
import matplotlib.pyplot as plt
df = vaex.open('data.hdf5')
# 简单直方图
df.plot1d(df.age)
# 自定义
df.plot1d(df.age,
limits=[0, 100],
shape=50, # 分箱数量
figsize=(10, 6),
xlabel='Age',
ylabel='Count')
plt.show()
### 二维密度图(热力图)
python
# 基础二维图
df.plot(df.x, df.y)
# 设置限制
df.plot(df.x, df.y, limits=[[0, 10], [0, 10]])
# 使用百分位数自动设置限制
df.plot(df.x, df.y, limits='99.7%') # 3-sigma 限制
# 自定义形状(分辨率)
df.plot(df.x, df.y, shape=(512, 512))
# 对数颜色刻度
df.plot(df.x, df.y, f='log')
### 散点图(小数据)
python
# 针对较小数据集或样本
df_sample = df.sample(n=1000)
df_sample.scatter(df_sample.x, df_sample.y,
alpha=0.5,
s=10) # 点大小
plt.show()
## 高级可视化选项
### 颜色刻度与归一化
python
# 线性刻度(默认)
df.plot(df.x, df.y, f='identity')
# 对数刻度
df.plot(df.x, df.y, f='log')
df.plot(df.x, df.y, f='log10')
# 平方根刻度
df.plot(df.x, df.y, f='sqrt')
# 自定义颜色映射
df.plot(df.x, df.y, colormap='viridis')
df.plot(df.x, df.y, colormap='plasma')
df.plot(df.x, df.y, colormap='hot')
### 限制与范围
python
# 手动限制
df.plot(df.x, df.y, limits=[[xmin, xmax], [ymin, ymax]])
# 基于百分位数的限制
df.plot(df.x, df.y, limits='99.7%') # 3-sigma
df.plot(df.x, df.y, limits='95%')
df.plot(df.x, df.y, limits='minmax') # 全范围
# 混合限制
df.plot(df.x, df.y, limits=[[0, 100], 'minmax'])
### 分辨率控制
python
# 高分辨率(更多分箱)
df.plot(df.x, df.y, shape=(1024, 1024))
# 低分辨率(更快)
df.plot(df.x, df.y, shape=(128, 128))
# Dif