Programing

매트릭리브 산점도의 개별 태그를 지정하는 방법?

c10106 2022. 3. 22. 21:12
반응형

매트릭리브 산점도의 개별 태그를 지정하는 방법?

나는 매트릭리브에서 산점도를 하려고 하는데 점들에 태그를 추가하는 방법을 찾을 수 없었다.예를 들면 다음과 같다.

scatter1=plt.scatter(data1["x"], data1["y"], marker="o",
                     c="blue",
                     facecolors="white",
                     edgecolors="blue")

나는 "y"의 점들이 "point 1", "point 2" 등으로 라벨을 붙이기를 원한다.저는 그것을 이해할 수 없었습니다.

plt.annotate:

import numpy as np
import matplotlib.pyplot as plt

N = 10
data = np.random.random((N, 4))
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()

여기에 이미지 설명을 입력하십시오.

참조URL: https://stackoverflow.com/questions/5147112/how-to-put-individual-tags-for-a-matplotlib-scatter-plot

반응형