import matplotlib.pyplot as plt import numpy as np import seaborn as sns # 设置美赛O奖风格 plt.rcParams['font.family'] = 'Times New Roman' plt.rcParams['font.size'] = 12 plt.rcParams['axes.labelsize'] = 12 plt.rcParams['axes.titlesize'] = 12 plt.rcParams['xtick.labelsize'] = 12 plt.rcParams['ytick.labelsize'] = 12 plt.rcParams['legend.fontsize'] = 12 plt.rcParams['figure.titlesize'] = 12 plt.rcParams['text.usetex'] = False # 如果系统未安装LaTeX,设为False plt.rcParams['axes.unicode_minus'] = False # 使用seaborn美化 sns.set_style("whitegrid") sns.set_context("paper") # 1. 准备数据 (模拟曲线) # 设定结束时间 T_verify t_verify = 13.43 # 生成 x 轴数据 (0 到 13.43) x = np.linspace(0, t_verify, 200) # 模拟放电曲线公式: y = 100 - k * x^n # 我们设终点为 (13.43, 5) 即剩下 5% 电量时结束 # 5 = 100 - k * (13.43)^1.8 (1.8 是为了模拟曲线的弧度) n = 1.7 # 调节这个指数可以改变曲线的弯曲程度 k = (100 - 5) / (t_verify ** n) y = 100 - k * (x ** n) # 2. 创建图表 (美赛标准尺寸,高DPI) # 使用 constrained_layout=True 自动处理布局防止文字遮挡 fig, ax = plt.subplots(figsize=(4, 3), dpi=300, constrained_layout=True) # 3. 绘制主曲线 (使用专业配色) # label 使用 LaTeX 格式渲染 T_verify ax.plot(x, y, color='#2E5090', linewidth=2.5, label=r'$T_{verify}=13.43$ h', zorder=3) # 4. 绘制阴影区域 # 填充曲线和 x 轴(y=0)之间的区域 ax.fill_between(x, y, 0, color='#2E5090', alpha=0.2, zorder=1) # 5. 绘制红色虚线 (阈值线) # 在 y=5 处画横线 ax.axhline(y=5, color='#C41E3A', linestyle='--', linewidth=2, zorder=2, label='Threshold (5%)') # 6. 设置标题 (已移除) # ax.set_title("Battery Discharge Profile: Browsing Mode (0.84W)", # fontsize=12, fontweight='bold', pad=15) # 7. 设置坐标轴标签 (美赛要求明确标注单位) ax.set_xlabel('Time (hours)', fontsize=12, fontweight='bold') ax.set_ylabel('Battery Capacity (%)', fontsize=12, fontweight='bold') # 8. 设置坐标轴范围 ax.set_xlim(0, 14.5) ax.set_ylim(0, 105) # 9. 设置坐标轴刻度 ax.set_xticks([0.0, 2.5, 5.0, 7.5, 10.0, 12.5]) ax.set_yticks([0, 20, 40, 60, 80, 100]) # 10. 设置网格 (美赛风格:淡雅背景网格) ax.grid(True, linestyle=':', alpha=0.3, color='gray', linewidth=0.8, zorder=0) ax.set_axisbelow(True) # 11. 设置图例 (专业风格) ax.legend(loc='upper right', fontsize=12, frameon=True, edgecolor='black', fancybox=False, shadow=False, framealpha=0.9) # 12. 美化边框 for spine in ax.spines.values(): spine.set_linewidth(1.2) spine.set_color('black') ax.tick_params(labelsize=12, width=1.2, length=6, direction='out') # 13. 调整布局并保存/显示 # 由于使用了constrained_layout,不需要手动调用tight_layout或adjust # 保存为高分辨率图片 (美赛推荐格式) plt.savefig('battery_discharge_profile.png', dpi=300, bbox_inches='tight', facecolor='white') plt.savefig('battery_discharge_profile.pdf', bbox_inches='tight', facecolor='white') plt.show()