Files
Feature-Extraction/heart_rate_2.py
2025-10-20 22:01:18 +08:00

28 lines
888 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import matplotlib.pyplot as plt
import numpy as np
# 1. 你的心率数据(示例 10 人,单位 bpm
# hr_data = [90.4,81.0,68.2,91.6,67.0,75.6,88.9,83.1,102.6] # (静息态)
hr_data = [102.3,85.7,70.7,103.6,72.9,76.0,90.3,91.5,105.0] # (运动后)
# 2. 基本统计
mean_hr = np.mean(hr_data)
std_hr = np.std(hr_data)
# 3. 画柱形图(直方图)
bins = np.arange(65, 110, 2) # 2 bpm 一个柱,范围可调
plt.figure(figsize=(6, 4))
n, bins, patches = plt.hist(hr_data, bins=bins, color='skyblue', edgecolor='black')
# 4. 美化
plt.title(f'Heart-Rate Distribution (n={len(hr_data)})')
plt.xlabel('Heart Rate (bpm)')
plt.ylabel('Count')
plt.xticks(bins)
plt.grid(axis='y', linestyle='--', alpha=0.6)
# 5. 把均值画成竖线
plt.axvline(mean_hr, color='red', linestyle='--', label=f'Mean = {mean_hr:.1f} bpm')
plt.legend()
plt.tight_layout()
plt.show()