import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

# 读取文件(注意:如果你的文件名有空格,请改一下)
df = pd.read_excel('OttaiCGM_24D660CE34D0.xlsx')
df['时刻'] = pd.to_datetime(df['时刻'], format='%Y.%m.%d %H:%M')
df = df.sort_values('时刻')

plt.figure(figsize=(15, 6))
plt.plot(df['时刻'], df['血糖值mmol/L'], linewidth=1.5, color='#0066cc', label='血糖值')

# 画三条关键线
plt.axhline(3.9, color='red', linestyle='--', linewidth=1, label='低血糖警戒 (3.9)')
plt.axhline(6.1, color='orange', linestyle='--', linewidth=1, label='正常上限 (6.1)')
plt.axhline(7.8, color='purple', linestyle='--', linewidth=1, label='需关注 (7.8)')

plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m-%d %H:%M'))
plt.gca().xaxis.set_major_locator(mdates.HourLocator(interval=6))
plt.xticks(rotation=45)
plt.xlabel('日期时间')
plt.ylabel('血糖 mmol/L')
plt.title('动态血糖监测曲线')
plt.legend(loc='upper left')
plt.grid(alpha=0.3)
plt.tight_layout()
plt.savefig('血糖曲线图.png', dpi=300)  # 保存高清图片
plt.show()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: