Initial commit

This commit is contained in:
ChuXun
2026-02-16 21:52:26 +08:00
commit 18ce59bec7
334 changed files with 35333 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
"""
Fig 15: User Guide Radar Chart
Compares different usage modes across multiple dimensions
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm # 导入字体管理模块
import seaborn as sns # 新增Seaborn库
def make_figure(config=None):
"""Generate Fig 15: User Guide Radar Chart优化指标文字距离"""
# ===================== 全局样式配置新增Seaborn + 字体/字号强制统一) =====================
# 设置Seaborn风格保持视觉一致性不修改核心样式
sns.set_style("whitegrid") # 启用Seaborn基础样式
sns.set_context("notebook", font_scale=1.0) # 基础上下文,字号不额外缩放
# 全局字体/字号强制配置(优先级最高)
plt.rcParams['font.family'] = 'Times New Roman' # 全局新罗马字体
plt.rcParams['font.size'] = 12 # 全局12号字
plt.rcParams['axes.unicode_minus'] = False # 兼容负号
# 补充Seaborn/Matplotlib全量字体覆盖
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
# 默认配置
if config is None:
config = {"global": {"figure_dir": "figures"}}
# 1. 定义雷达图维度与数据(原逻辑不变)
categories = ['Battery Life', 'Performance', 'Display Quality',
'Connectivity', 'User Experience']
n_cats = len(categories)
power_saver = [4.5, 2.0, 2.5, 2.0, 2.5] # 省电模式
high_performance = [1.5, 5.0, 5.0, 4.5, 4.0] # 高性能模式
# 闭合多边形(雷达图需首尾相连)
power_saver += power_saver[:1]
high_performance += high_performance[:1]
# 2. 计算角度(原逻辑不变)
angles = np.linspace(0, 2 * np.pi, n_cats, endpoint=False).tolist()
angles += angles[:1] # 闭合角度列表
# 3. 创建极坐标图(原逻辑不变)
fig, ax = plt.subplots(figsize=(10, 10), subplot_kw=dict(projection='polar'))
# 4. 绘制雷达图数据(原逻辑不变)
ax.plot(angles, power_saver, 'o-', linewidth=2.5, label='Power Saver Mode',
color='#2ca02c', markersize=8)
ax.fill(angles, power_saver, alpha=0.25, color='#2ca02c')
ax.plot(angles, high_performance, 's-', linewidth=2.5, label='High Performance Mode',
color='#d62728', markersize=8)
ax.fill(angles, high_performance, alpha=0.25, color='#d62728')
# 5. 调整极坐标轴方向(原逻辑不变)
ax.set_theta_offset(np.pi / 2)
ax.set_theta_direction(-1)
# ========== 指标文字强制12pt + 新罗马字体(兜底保障) ==========
ax.set_xticks(angles[:-1])
ax.set_xticklabels([])
for angle, label in zip(angles[:-1], categories):
r = 5.2
ha = 'center'
va = 'center'
if angle < np.pi/2:
ha = 'left'
va = 'bottom'
elif angle < np.pi:
ha = 'left'
va = 'top'
elif angle < 3*np.pi/2:
ha = 'right'
va = 'top'
else:
ha = 'right'
va = 'bottom'
# 指标文字:显式指定字体和字号(全局已设,此处兜底)
ax.text(angle, r, label,
fontsize=12,
fontfamily='Times New Roman',
ha=ha, va=va, weight='bold')
# 6. 设置径向轴强制12pt新罗马字体
ax.set_ylim(0, 5)
ax.set_yticks([1, 2, 3, 4, 5])
ax.set_yticklabels(['1', '2', '3', '4', '5'],
fontsize=12, # 12号字
fontfamily='Times New Roman') # 新罗马字体
ax.set_rlabel_position(18)
# 7. 网格与样式结合Seaborn风格保持原逻辑
ax.grid(True, linewidth=0.5, alpha=0.5)
# ========== 8. 图例强制12pt + 新罗马字体 ==========
# 步骤1创建字体属性对象指定字体和字号
legend_font = fm.FontProperties(
family='Times New Roman', # 新罗马字体
size=12 # 12号字
)
# 步骤2通过prop参数传入字体属性核心保障
ax.legend(
loc='upper right',
bbox_to_anchor=(1.2, 1.0),
framealpha=0.9,
prop=legend_font, # 替代fontfamily用prop传字体属性
borderaxespad=0.1
)
# 9. 调整布局(原逻辑不变)
plt.tight_layout()
# 10. 显示图片
plt.show()
# 返回计算指标(原逻辑不变)
return {
"computed_metrics": {
"power_saver_score": float(np.mean(power_saver[:-1])),
"high_performance_score": float(np.mean(high_performance[:-1])),
"battery_life_advantage": float(power_saver[0] - high_performance[0])
},
"pass": True
}
# 直接运行显示图片
if __name__ == "__main__":
make_figure()