[ PROMPT_NODE_26906 ]
plotting_guide
[ SKILL_DOCUMENTATION ]
# 绘图指南
从 Neuropixels 数据创建出版级可视化图表的综合指南。
## 设置
python
import matplotlib.pyplot as plt
import numpy as np
import spikeinterface.full as si
import spikeinterface.widgets as sw
import neuropixels_analysis as npa
# 高质量设置
plt.rcParams['figure.dpi'] = 150
plt.rcParams['savefig.dpi'] = 300
plt.rcParams['font.size'] = 10
plt.rcParams['font.family'] = 'sans-serif'
## 漂移和运动图表
### 基础漂移图
python
# 使用 npa
npa.plot_drift(recording, output='drift_map.png')
# 使用 SpikeInterface 工具
from spikeinterface.preprocessing import detect_peaks, localize_peaks
peaks = detect_peaks(recording, method='locally_exclusive')
peak_locations = localize_peaks(recording, peaks, method='center_of_mass')
sw.plot_drift_raster_map(
peaks=peaks,
peak_locations=peak_locations,
recording=recording,
clim=(-50, 50),
)
plt.savefig('drift_raster.png', bbox_inches='tight')
### 运动估算可视化
python
motion_info = npa.estimate_motion(recording)
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
# 随时间变化的运动
ax = axes[0]
for i in range(motion_info['motion'].shape[1]):
ax.plot(motion_info['temporal_bins'], motion_info['motion'][:, i], alpha=0.5)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Motion (um)')
ax.set_title('Estimated Motion')
# 运动直方图
ax = axes[1]
ax.hist(motion_info['motion'].flatten(), bins=50, edgecolor='black')
ax.set_xlabel('Motion (um)')
ax.set_ylabel('Count')
ax.set_title('Motion Distribution')
plt.tight_layout()
plt.savefig('motion_analysis.png', dpi=300)
## 波形图表
### 单单元波形
python
unit_id = 0
# 基础波形
sw.plot_unit_waveforms(analyzer, unit_ids=[unit_id])
plt.savefig(f'unit_{unit_id}_waveforms.png')
# 带密度图
sw.plot_unit_waveform_density_map(analyzer, unit_ids=[unit_id])
plt.savefig(f'unit_{unit_id}_density.png')
### 模板比较
python
# 比较多个单元
unit_ids = [0, 1, 2, 3]
sw.plot_unit_templates(analyzer, unit_ids=unit_ids)
plt.savefig('template_comparison.png')
### 探针上的波形
python
# 在探针上空间展示波形
sw.plot_unit_waveforms_on_probe(
analyzer,
unit_ids=[unit_id],
plot_channels=True,
)
plt.savefig(f'unit_{unit_id}_probe.png')
## 质量指标可视化
### 指标概览
python
npa.plot_quality_metrics(analyzer, metrics, output='quality_overview.png')
``