이 질문은 this에 이어집니다. 레이블이 지정된 지점이 정확히 일치하거나 거의 일치 할 때 주석을 여전히 읽을 수 있도록 배치하려면 어떻게해야합니까? 프로그래밍 방식의 솔루션이 필요합니다. 오프셋 튜닝은 옵션이 아닙니다. 추한 라벨 샘플 :일치점/겹치는 주석이있는 Pyplot Label Scatter Plot
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
N = 10
data = np.random.random((N, 4))
data[1, :2] = data[0, :2]
data[-1, :2] = data[-2, :2] + .01
labels = ['point{0}'.format(i) for i in range(N)]
plt.subplots_adjust(bottom = 0.1)
plt.scatter(
data[:, 0], data[:, 1], marker = 'o', c = data[:, 2], s = data[:, 3]*1500,
cmap = plt.get_cmap('Spectral'))
for label, x, y in zip(labels, data[:, 0], data[:, 1]):
plt.annotate(
label,
xy = (x, y), xytext = (-20, 20),
textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
plt.show()
나는하기 matplotlib가 자동으로이 작업을 수행 할 것입니다 확신 해요. 레이블이 교차하지 않도록 레이블의 각도를 반복적으로 결정해야합니다. 이것은 어려운 작업입니다. 특히 유효한 솔루션에 대한 보장이 없기 때문입니다. 점이 다른 점으로 둘러싸여 있으면 특정 반경 내에 레이블을 실제로 배치 할 수 없습니다. 나는 당신이 처음부터 경험적으로 만들어야한다고 믿는다. –