对比试验可视化,气泡图

import matplotlib.pyplot as plt

# 示例数据
algorithms = ['Algorithm A', 'Algorithm B', 'Algorithm C', 'Algorithm D']
compute = [1.2e9, 2.5e9, 3.0e9, 0.8e9]  # 计算量(FLOPs)
map_scores = [0.75, 0.82, 0.68, 0.90]    # mAP值
params = [5e6, 12e6, 8e6, 3e6]          # 参数量

# 数据验证
if len(algorithms) != len(compute) or len(algorithms) != len(map_scores) or len(algorithms) != len(params):
    raise ValueError("所有输入列表的长度必须一致。")

# 调整参数量的显示大小
scaled_params = [p / 1e4 for p in params]

# 创建图表
plt.figure(figsize=(12, 8), dpi=100)
colors = plt.cm.tab10.colors[:len(algorithms)]

# 绘制气泡图
scatter = plt.scatter(
    x=compute,
    y=map_scores,
    s=scaled_params,
    c=colors,
    alpha=0.7,
    edgecolors='w',
    linewidths=1.5
)

# 添加算法名称标签
for i, (x, y) in enumerate(zip(compute, map_scores)):
    plt.annotate(
        algorithms[i],
        (x, y),
        xytext=(5, 5),
        textcoords='offset points',
        ha='center',
        fontsize=9
    )

# 设置坐标轴格式
plt.gca().xaxis.set_major_formatter(lambda x, _: f'{x / 1e9:.1f}G')
plt.xlabel('Computational Load (GFLOPs)')
plt.ylabel('mAP Score')
plt.title('Algorithm Comparison\n(Bubble Size = Parameters)')
plt.grid(True, linestyle='--', alpha=0.6)

# 创建算法图例
algo_legend = plt.legend(
    handles=[
        plt.scatter([], [], s=50, color=color, label=algo, alpha=0.7)
        for algo, color in zip(algorithms, colors)
    ],
    title='Algorithms',
    loc='upper left',
    bbox_to_anchor=(1.05, 1)
)

# 创建参数量图例
param_legend = plt.legend(
    handles=[
        plt.scatter([], [], s=s / 1e4, color='gray', alpha=0.7, label=f'{int(s / 1e6)}M')
        for s in [3e6, 6e6, 9e6, 12e6]  # 示例参数值
    ],
    title='Parameters',
    loc='upper left',
    bbox_to_anchor=(1.05, 0.7)
)

# 将算法图例和参数量图例添加到图表
plt.gca().add_artist(algo_legend)
plt.gca().add_artist(param_legend)

# 保存图片
plt.savefig('algorithm_comparison.png', bbox_inches='tight')

plt.tight_layout()
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值