
代码绘制成果展示













代码解释


第一部分

# =========================================================================================# ====================================== 1. 环境设置 =======================================# =========================================================================================import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom matplotlib.lines import Line2Dimport matplotlib

第二部分

# =========================================================================================# ======================================2.颜色库=======================================# =========================================================================================COLOR_SCHEMES = {1: ['#C83E4D', '#F4B38C', '#D0E1F9', '#85C1E9', '#2E86C1', '#5A306D', '#C45B90', '#8B3E4F'],}

第三部分

# =========================================================================================# ======================================3.绘图函数=======================================# =========================================================================================def plot_advanced_forest_chart(df_real, scheme_id):selected_colors = COLOR_SCHEMES[scheme_id] # 获取配色方案# 分配颜色label_colors = df_real['Label_Color'].map(category_color_map).tolist() # 各标签对应颜色

第四部分

model_columns = ['EAGLE', 'CHIEF', 'GigaPath', 'CTransPath', 'Virchow2'] #指定参与对比列df_plot = df_real.copy() #创建数据副本#将真实数值除以该轴最大范围,等比例映射到的绘图物理半径内for col in model_columns:df_plot[col] = df_real[col] / max_vals_series

第五部分

# 创建画布fig, ax = plt.subplots(figsize=(15, 15), subplot_kw=dict(polar=True))ax.set_xticks(angles[:-1]) # x轴刻度ax.set_xticklabels([]) # 去掉x轴默认标签# 径向线ax.xaxis.grid(True, # 开启color='#d3d3d3', # 颜色linestyle='-', # 线型linewidth=1) # 线宽

第六部分

r_positions = [0.4, 0.6, 0.8, 1.00] # 定义显示的径向物理比例刻度ax.text(angle, # xr, # yf"{actual_val:.2f}", #文本pad=0.3)) # 内边距

第七部分

# 遍历绘制外围标签for i, () in enumerate():# 绘制外圈文本ax.text(angle, # 角度label_radius, # 半径label_text, # 文本size=10, # 字体大小color='white', # 字体颜色weight='bold', # 粗体bbox=dict(boxstyle="round,pad=0.3", # 圆角alpha=0.95)) # 透明度

第八部分

# =========================================================================================# ======================================4.执行部分=======================================# =========================================================================================if __name__ == '__main__':df_real = pd.read_excel(r'data.xlsx') # 读取数据scheme_id = 1selected_hex_colors = COLOR_SCHEMES[scheme_id]print('正在绘制并保存方案:', scheme_id)plot_advanced_forest_chart(df_real, scheme_id)

如何应用到你自己的数据

1.设置原始数据的保存路径,执行部分:
df_real = pd.read_excel(r'data.xlsx') 2.设置是否要进行批量绘图,执行部分:
plot_all = True3.设置要进行绘图的数据列,绘图函数部分:
model_columns = ['EAGLE', 'CHIEF', 'GigaPath', 'CTransPath', 'Virchow2'] 4.设置绘图结果的保存地址,绘图函数部分:
plt.savefig(fr'Scheme_{scheme_id}.png', dpi=300, bbox_inches='tight')
推荐


获取方式
