ComputerLanguage_Program/PYTHON
[PYTHON] offsetbox 를 이용한 피카츄(이미지) 산점도 그리기
pbj0812
2021. 7. 30. 01:14
0. 목표
- offsetbox 를 이용한 피카츄(이미지) 산점도 그리기
1. 실습
1) library 호출
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
2) 데이터 생성
- x : x 좌표
- y : y 좌표
- z : 크기
x = [3, 8, 5, 9, 4]
y = [8, 3, 4, 8, 2]
z = [7, 2, 3, 4, 5]
3) 그래프 그리기
(1) 도화지 생성
(2) 피카츄 그림 호출
(3) 반복문을 이용해 x, y, z 데이터를 하나씩 들고오면서 그림 생성
# 1
fig, ax = plt.subplots()
fig.set_size_inches(15, 15)
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
# 2
pika = mpimg.imread('./pika.png')
# 3
for i in range(len(x)):
imagebox = OffsetImage(pika, zoom = 0.1 * z[i])
ab = AnnotationBbox(imagebox, (x[i], y[i]), frameon = False)
ax.add_artist(ab)
- 결과
2. 참고
- How to insert an image (a picture or a photo) in a matplotlib figure