ComputerLanguage_Program/PYTHON
[PYTHON] indicate_inset_zoom 을 이용한 줌 인
pbj0812
2021. 8. 12. 03:07
0. 목표
- indicate_inset_zoom 을 이용한 줌 인
1. 실습
1) library 호출
import matplotlib.pyplot as plt
import numpy as np
2) 데이터 생성
- 줌인할 데이터(5 * 5)
small = np.array([
[1.0, 0.5, 1.0, 0.1, 0.3],
[0.5, 0.5, 0.5, 0.2, 0.4],
[1.0, 0.5, 1.0, 0.3, 0.6],
[0.5, 0.5, 0.5, 0.2, 0.4],
[1.0, 0.5, 1.0, 0.1, 0.3]
])
- 0으로 이루어진 전체 데이터(200 * 200)
- 50, 70 지점에 small 데이터를 얹는 형태
big = np.zeros((200, 200))
ny, nx = small.shape
big[50:50+ny, 70:70+nx] = small
3) 그림 그리기
# 도화지
fig, ax = plt.subplots()
fig.set_size_inches(15, 15)
# 대형 그림 그리기, lower 를 넣으면 위아래가 뒤바뀜
ax.imshow(big, origin="lower")
# 작은 도화지, 큰 도화지의 0.5, 0.5 의 위치에서부터 0.4, 0.4 만큼의 크기의 도화지를 만듦
axins = ax.inset_axes([0.5, 0.5, 0.4, 0.4])
# 작은 도화지에 큰 그림을 그림
axins.imshow(big, origin="lower")
# xlim, ylim 을 조정하여 무늬가 속하도록 만듦
x1, x2, y1, y2 = 69.5, 74.5, 49.5, 54.5
axins.set_xlim(x1, x2)
axins.set_ylim(y1, y2)
# 줌인 느낌의 그림
ax.indicate_inset_zoom(axins, edgecolor="w", linewidth = 4)
- 결과