matplotlib의 annotate는 지정된 xy위치에 text를 삽입해주는 함수입니다.
파라미터 | 설명 |
text : str | 추가할 문자열 |
xy : (float, float) | 추가할 (x, y) 위치 |
xytext : (float, float) | xy위치에서 조정할 텍스트 위치 |
textcoords : str or Artist or Transform or (float, float) | - default: value of xycoords xytext가 제공되는 좌표계 'offset points': xy값으로부터의 offset(point) 'offset pixels': xy값으로부터의 offset(pixel) |
annotate와 산점도를 사용하면 다음과 같이 정보를 표현할 수 있습니다.
import matplotlib.pyplot as plt
friends = [70, 65, 72, 63, 71, 64, 60, 64, 67]
minutes = [175, 170, 205, 120, 220, 130, 105, 145, 190]
labels = [chr(97 + i) for i in range(len(friends))]
plt.scatter(friends, minutes)
for label, friend_count, minute_count in zip(labels, friends, minutes):
plt.annotate(label,
xy=(friend_count, minute_count),
xytext=(5, -5),
textcoords='offset points')
plt.show()
참고
밑바닥부터 시작하는 데이터과학2판, 조엘 그루스
'Python > Syntax' 카테고리의 다른 글
[Python] Dictionary 대신 사용할 수 있는 NamedTuple (NamedTuple Type Annotation) (0) | 2022.09.10 |
---|---|
[colab] colab에서 ipynb파일 import하기 (0) | 2022.09.02 |
[Pandas] DataFrame 조건부 검색 시 주의사항 (0) | 2022.08.19 |
[Pandas] read_csv에서 index_col 삭제 (0) | 2022.08.19 |
[JupyterNoteBook] 사용자 정의 ipynb 파일 임포트 (다른 ipynb 파일 임포트) (0) | 2022.07.29 |