import matplotlib.pyplot as plt import matplotlib.dates as mdates from datetime import datetime plt.rcParams['font.sans-serif'] = ['PingFang SC', 'Hiragino Sans GB', 'Arial Unicode MS', 'STHeiti'] plt.rcParams['axes.unicode_minus'] = False dates = [ datetime(2020, 4, 1), datetime(2020, 10, 1), datetime(2021, 2, 12), datetime(2021, 8, 1), datetime(2022, 1, 1), datetime(2022, 6, 1), datetime(2023, 5, 1), datetime(2023, 5, 2), datetime(2023, 10, 1), datetime(2024, 3, 1), datetime(2024, 9, 1), datetime(2025, 3, 1), datetime(2025, 10, 27), datetime(2026, 4, 19), ] prices = [40, 65, 113.51, 60, 35, 17, 17.5, 9, 10, 5, 2.5, 1.8, 1.2, 0.61] fig, ax = plt.subplots(figsize=(12, 6.5), facecolor='#0d1117') ax.set_facecolor('#0d1117') ax.plot(dates, prices, color='#ff4d4d', linewidth=2.8, zorder=3) ax.fill_between(dates, prices, color='#ff4d4d', alpha=0.18, zorder=2) events = [ (datetime(2021, 2, 12), 113.51, '2021-02\n历史高点 $113.51', (180, 8), 'bottom', 'left'), (datetime(2023, 5, 2), 9, '2023-05 ChatGPT 冲击\n财报日单日跌 48%', (180, 25), 'bottom', 'left'), (datetime(2025, 10, 27), 1.2, '2025-10 二轮裁员 -45%', (-60, 35), 'bottom', 'right'), (datetime(2026, 4, 19), 0.61, '2026-04 $0.61\n累计跌 99%', (-20, 55), 'bottom', 'right'), ] for dt, p, label, offset_days, va, ha in events: from datetime import timedelta xtext = dt + timedelta(days=offset_days[0]) ytext = p + offset_days[1] ax.annotate( label, xy=(dt, p), xytext=(xtext, ytext), color='#ffd166', fontsize=10, ha=ha, va=va, fontweight='bold', arrowprops=dict(arrowstyle='->', color='#ffd166', lw=1.2), ) ax.scatter([dt], [p], color='#ffd166', s=55, zorder=4, edgecolors='#ff4d4d', linewidth=1.5) ax.set_title('Chegg (CHGG) 股价 5 年雪崩:$113.51 → $0.61 (-99%)', color='white', fontsize=17, pad=20, fontweight='bold') ax.set_ylabel('股价 (USD)', color='#c9d1d9', fontsize=12) ax.set_xlabel('', color='#c9d1d9') ax.tick_params(colors='#c9d1d9', labelsize=11) for spine in ax.spines.values(): spine.set_color('#30363d') ax.grid(True, alpha=0.25, color='#30363d', linestyle='--') ax.xaxis.set_major_locator(mdates.YearLocator()) ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y')) ax.set_ylim(-5, 140) fig.text(0.5, 0.01, '数据来源:Yahoo Finance / Macrotrends', color='#6e7681', fontsize=8, ha='center', va='bottom', style='italic') plt.tight_layout() plt.savefig('/Users/bing/work/code/myself/self-media-james/articles/013/chegg-stock.png', dpi=150, facecolor='#0d1117', bbox_inches='tight') print('Chegg chart saved')