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()

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

你可能感兴趣的:(深度学习,深度学习,人工智能,python)