多种网络圆形性能图——帮你冲击CVPR、ECCV、ICCV

1. 引言

你是否也想问,CVPR论文中第一页的图是怎么画的,这里为你提供了代码,只需稍微的改动即可实现

2. 效果图

在这里插入图片描述
在这里插入图片描述

3. 代码实现

  1. 没有注释,如图1所示
  2. 带有注释,如图2所示

代码如下:

3.1 不带注释 —— 如图1

import os.path
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['Times New Roman']
"""
        x: x轴的数据 —— 网络的速度
            * x_A
            * x_B

        y: y轴的数据 —— 网络的top-1准确率
            * y_A
            * y_B

        不同的形状代表的含义:网络的参数量
            circle(圆形):  
                * circle_size
            star(三角形):
                * star_size
"""

"""====== [x -> 速度] ======"""
x_A = [100, 105, 111, 132, 108, 145]
x_B = [200, 222, 241, 210, 240, 207]

"""====== [y -> top-1准确率] ======"""
y_A = [96, 92, 92, 91, 95, 93]
y_B = [93, 90, 88, 89, 92, 87]

"""====== [circle -> 参数量] ======"""
# 如果大小不合适,调整factor
factor_A = 5
circle_size = [i * factor_A for i in [110, 70, 65, 90, 140, 65]]

"""====== [star -> 参数量] ======"""
# 如果大小不合适,调整factor
factor_B = 5
star_size = [i * factor_B for i in [55, 34, 30, 40, 60, 30]]

# 形状的颜色变化
color_size = [0, 1, 2, 3, 4, 5]

# 定义保存图片的路径
fig_path = "./res"
file_name = "examples_without_annotation.svg"
save_path = os.path.join(fig_path, file_name)
print(save_path)

if not os.path.exists(fig_path):
    os.mkdir(fig_path)

"""====== [开始绘制] ======
    https://matplotlib.org/stable/api/markers_api.html
"""
fig, ax = plt.subplots()
scatter_A = plt.scatter(x_A, y_A, c=color_size, s=circle_size, marker='o')  # x, y, c多种网络圆形性能图——帮你冲击CVPR、ECCV、ICCVolor, shape
scatter_B = plt.scatter(x_B, y_B, c=color_size, s=star_size, marker="*")  # x, y, color, shape

# 隐藏rt和r的框线
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

# x和y轴的名称
plt.xlabel("x-axis/unit")
plt.ylabel("y-axis/unit")

plt.tight_layout()
"""
保存图片
    https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html?highlight=savefig#matplotlib.pyplot.savefig
"""
plt.savefig(save_path)  # 保存图片
print(f"Figure has been saved in [{str(save_path)}]")
plt.show()

3.2 带有注释 —— 如图2

import os.path
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['Times New Roman']
"""
        x: x轴的数据 —— 网络的速度
            * x_A
            * x_B

        y: y轴的数据 —— 网络的top-1准确率
            * y_A
            * y_B

        不同的形状代表的含义:网络的参数量
            circle(圆形):  
                * circle_size
            star(三角形):
                * star_size
"""

"""====== [x -> 速度] ======"""
x_A = [100, 105, 111, 132, 108, 145]
x_B = [200, 222, 241, 210, 240, 207]

"""====== [y -> top-1准确率] ======"""
y_A = [96, 92, 92, 91, 95, 93]
y_B = [93, 90, 88, 89, 92, 87]

"""====== [circle -> 参数量] ======"""
# 如果大小不合适,调整factor
factor_A = 5
circle_size = [i * factor_A for i in [110, 70, 65, 90, 140, 65]]

"""====== [star -> 参数量] ======"""
# 如果大小不合适,调整factor
factor_B = 5
star_size = [i * factor_B for i in [55, 34, 30, 40, 60, 30]]

"""====== [annotation的信息] ======"""
txt_v1 = ['A-1', 'A-2', 'A-3', 'A-4', 'A-5', 'A-6']
txt_v2 = ['B-1', 'B-2', 'B-3', 'B-4', 'B-5', 'B-6']

# 形状的颜色变化
color_size = [0, 1, 2, 3, 4, 5]

# 定义保存图片的路径
fig_path = "./res"
file_name = "examples_with_annotation.svg"
save_path = os.path.join(fig_path, file_name)
print(save_path)

if not os.path.exists(fig_path):
    os.mkdir(fig_path)

"""====== [开始绘制] ======
    https://matplotlib.org/stable/api/markers_api.html
"""
fig, ax = plt.subplots()
scatter_A = plt.scatter(x_A, y_A, c=color_size, s=circle_size, marker='o')  # x, y, color, shape
scatter_B = plt.scatter(x_B, y_B, c=color_size, s=star_size, marker="*")  # x, y, color, shape

# 隐藏rt和r的框线
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

# x和y轴的名称
plt.xlabel("x-axis/unit")
plt.ylabel("y-axis/unit")

"""========================================= [net_1] ========================================="""
offset_A = 0.7
for i in range(len(circle_size)):
    if i == 0:  # 第一个圆
        plt.annotate(txt_v1[i],
                     xy=(x_A[i], y_A[i]),
                     xytext=(x_A[i] + 10, y_A[i] - 0.1),
                     xycoords='data',
                     arrowprops=dict(arrowstyle='|-|, widthA=0,widthB=0', connectionstyle='arc3,rad=0', color="0.5"),
                     )
    elif i == 1:  # 第二个圆
        plt.annotate(txt_v1[i],
                     xy=(x_A[i], y_A[i]),
                     xytext=(x_A[i] - 10, y_A[i] - 1),
                     xycoords='data',
                     arrowprops=dict(arrowstyle='|-|, widthA=0,widthB=0', connectionstyle='arc3,rad=0', color="0.5"),
                     )
    elif i == 3:  # 第4个圆
        plt.annotate(txt_v1[i],
                     xy=(x_A[i], y_A[i]),
                     xytext=(x_A[i] + 10, y_A[i] - 0.1),
                     xycoords='data',
                     arrowprops=dict(arrowstyle='|-|, widthA=0,widthB=0', connectionstyle='arc3,rad=0', color="0.5"),
                     )
    elif i == 4:  # 第5个圆
        plt.annotate(txt_v1[i],
                     xy=(x_A[i], y_A[i]),
                     xytext=(x_A[i] + 4, y_A[i] - 1),
                     xycoords='data',
                     arrowprops=dict(arrowstyle='|-|, widthA=0,widthB=0', connectionstyle='arc3,rad=0', color="0.5"),
                     )
    elif i == 5:  # 第6个圆
        plt.annotate(txt_v1[i],
                     xy=(x_A[i], y_A[i]),
                     xytext=(x_A[i] - 0.1, y_A[i] + 1.0),
                     xycoords='data',
                     arrowprops=dict(arrowstyle='|-|, widthA=0,widthB=0', connectionstyle='arc3,rad=0', color="0.5"),
                     )
    else:
        plt.annotate(txt_v1[i],
                     xy=(x_A[i], y_A[i]),
                     xytext=(x_A[i] + offset_A, y_A[i] + offset_A),
                     xycoords='data',
                     # textcoords='offset pixels',
                     # textcoords='data',
                     arrowprops=dict(arrowstyle='|-|, widthA=0,widthB=0', connectionstyle='arc3,rad=0', color="0.5"),
                     # fontsize=16,
                     # arrowprops=dict(arrowstyle='->, head_length=0.4, head_width=0.2', connectionstyle='arc3,rad=0')
                     # arrowprops=dict(arrowstyle='wedge, tail_width=0.3, shrink_factor=0.5', connectionstyle='arc3,rad=0')
                     # arrowprops=dict(arrowstyle='fancy, head_length=0.4, head_width=0.4, tail_width=0.4', connectionstyle='arc3,rad=0')
                     # arrowprops=dict(arrowstyle='simple, head_length=0.5, head_width=0.5, tail_width=0.2', connectionstyle='arc3,rad=0')
                     )

"""========================================= [net_2] ========================================="""
offset_B = 1
for i in range(len(star_size)):
    plt.annotate(txt_v2[i],
                 xy=(x_B[i], y_B[i]),
                 xytext=(x_B[i] + offset_B, y_B[i] + offset_B),
                 xycoords='data',
                 # textcoords='offset pixels',
                 textcoords='data',
                 arrowprops=dict(arrowstyle='|-|, widthA=0,widthB=0', connectionstyle='arc3,rad=0', color="0.5"),
                 )

plt.tight_layout()
"""
保存图片
    https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html?highlight=savefig#matplotlib.pyplot.savefig
"""
plt.savefig(save_path)  # 保存图片
print(f"Figure has been saved in [{str(save_path)}]")
plt.show()

4. 补充

  1. 代码很简单,无需讲解😂
  2. 输出图片格式可以调节,详情见Matplotlib文档
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值