adjustText库解决深度学习、视觉模型matplotlib画散点图时由于标签非常多导致的重叠现象

pytorch框架

import matplotlib.pyplot as plt
import numpy as np
from adjustText import adjust_text

y = [30.48, 30.71, 30.52, 31.35, 31.53, 31.54, 31.82, 32.13, 32.21, 32.15, 31.92, 32.24, 32.21, 32.20, 32.35]
x = [0.057, 0.012, 0.025, 0.665, 1.774, 0.813, 0.553, 1.592, 0.715, 0.659, 0.603, 0.550, 0.411, 0.543, 0.497]
labels = ['SRCNN', 'FSRCNN', 'ESPCN', 'VDSR', 'DRCN', 'LapSRN', 'IDN', 'CRAN', 'IMDN', 'LAPAR-A', 'ECBSR', 'RFDN',
          'ShuffleMixer', 'DIPNet', '(Ours)']
colors = ['b', 'g', 'c', 'y', 'm', 'k', 'grey', 'dodgerblue', 'indianred', 'peru', 'springgreen', 'purple', 'chartreuse',
          'moccasin']

fig, ax = plt.subplots()

# 绘制除Ours的其他点
ax.scatter(x[:-1], y[:-1], s=75, c=colors)

# 自己模型单独标出; rotation调整旋转角度; weight加租
ax.scatter(x[-1], y[-1], s=75, c='r', marker='*')
ax.text(x[-1], y[-1], labels[-1], weight='bold', ha='center', rotation=8)

# 利用adjustText库调整文本位置防止重叠 pip install adjustText
texts = []
for i in range(len(labels) - 1): #colors比其他的少一个对象
    text = ax.text(x[i], y[i], labels[i], ha='left')
    texts.append(text)
adjust_text(texts, arrowprops=dict(arrowstyle='->', color='black', lw=0.7))



ax.set_xlabel('X')
ax.set_ylabel('Y')

ax.set_ylim(30, 33)  
ax.set_xlim(0, 1.8)

plt.show()

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值