import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from scipy.ndimage import gaussian_filter1d

# 示例成绩数据（可替换）
np.random.seed(0)
dates = np.arange(1, 13)  # 12 次考试或 12 个月
scores = np.clip(70 + np.cumsum(np.random.randn(len(dates)) * 3), 50, 100)

# 做平滑以获得更“未来”的流线感
scores_smooth = gaussian_filter1d(scores, sigma=1.5)

# 创建未来感背景渐变
fig, ax = plt.subplots(figsize=(10, 5), dpi=120)
fig.patch.set_facecolor('#0b1020')  # 深夜蓝背景

# 背景渐变（纵向）
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))
from matplotlib.transforms import Bbox
ax.imshow(gradient.T, aspect='auto',
          cmap=LinearSegmentedColormap.from_list('bg', ['#0b1020', '#061428', '#001220']),
          extent=[dates.min()-0.5, dates.max()+0.5, 40, 105],
          alpha=0.9, zorder=0)

# 网格线（细致、虚线）
ax.set_facecolor('none')
ax.grid(which='major', color='#16324a', linestyle='--', linewidth=0.6, zorder=1)

# 渐变线条：用多段小线段模拟渐变
cmap_line = LinearSegmentedColormap.from_list('neon', ['#00f5ff', '#6a00ff', '#ff00d0'])
for i in range(len(dates)-1):
    x_seg = dates[i:i+2]
    y_seg = scores_smooth[i:i+2]
    t = i / (len(dates)-2) if len(dates)>2 else 0
    color = cmap_line(t)
    # 画多层线条以制造发光晕
    ax.plot(x_seg, y_seg, color=color, linewidth=6, solid_capstyle='round', alpha=0.12, zorder=3)
    ax.plot(x_seg, y_seg, color=color, linewidth=3, solid_capstyle='round', alpha=0.25, zorder=4)
    ax.plot(x_seg, y_seg, color=color, linewidth=2.2, solid_capstyle='round', alpha=1.0, zorder=5)

# 标记点：外发光 + 中心点
for x, y in zip(dates, scores_smooth):
    ax.scatter(x, y, s=300, color='#ffffff', alpha=0.05, zorder=2)  # 大光晕
    ax.scatter(x, y, s=80, color='#ffffff', alpha=0.18, zorder=6)
    ax.scatter(x, y, s=18, color='#0ff0ff', edgecolor='white', linewidth=0.8, zorder=7)

# 标注末点分数
ax.text(dates[-1]+0.3, scores_smooth[-1], f'{scores[-1]:.0f}', color='white',
        fontsize=12, va='center', zorder=8, fontweight='bold')

# 轴与标签美化
ax.set_xlim(dates.min()-0.5, dates.max()+1)
ax.set_ylim(45, 102)
ax.set_xticks(dates)
ax.set_xticklabels([f'第{int(d)}次' for d in dates], color='#c7e9ff')
ax.set_yticks([50,60,70,80,90,100])
ax.set_yticklabels([50,60,70,80,90,100], color='#c7e9ff')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#102a3a')
ax.spines['bottom'].set_color('#102a3a')
ax.tick_params(colors='#9fd8ff')

# 标题
ax.set_title('成绩走势图 — 未来风', color='white', fontsize=16, pad=14, fontweight='bold')

plt.tight_layout()
plt.show()