matplotlib에서 컬러바에 애니메이션을 적용하려면 다음 단계를 수행할 수 있습니다. -
-
Figure 크기를 설정하고 서브플롯 사이와 주변의 패딩을 조정합니다.
-
새 그림을 만들거나 기존 그림을 활성화하세요.
-
'~.axes.Axes' 추가 하위 플롯 배열의 일부로 그림에.
-
디바이더 인스턴스화 기존 축, 즉 ax 객체를 기반으로 지정된 셀에 대한 새 축 로케이터를 반환합니다.
-
주어진 *위치*에 축 생성 동일한 높이로 (또는 너비 ) 주축.
-
numpy를 사용하여 임의의 데이터를 생성합니다.
-
imshow() 사용 임의의 데이터를 플롯하는 방법입니다.
-
줄거리의 제목을 설정합니다.
-
컬러맵 목록을 인스턴스화합니다.
-
컬러바에 애니메이션을 적용하려면 animate()를 사용하세요. 방법.
-
그림을 표시하려면 show()를 사용하세요. 방법.
예
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.axes_grid1 import make_axes_locatable
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(111)
div = make_axes_locatable(ax)
cax = div.append_axes('right', '5%', '5%')
data = np.random.rand(5, 5)
im = ax.imshow(data)
cb = fig.colorbar(im, cax=cax)
tx = ax.set_title('Frame 0')
cmap = ["copper", 'RdBu_r', 'Oranges', 'cividis', 'hot', 'plasma']
def animate(i):
cax.cla()
data = np.random.rand(5, 5)
im = ax.imshow(data, cmap=cmap[i%len(cmap)])
fig.colorbar(im, cax=cax)
tx.set_text('Frame {0}'.format(i))
ani = animation.FuncAnimation(fig, animate, frames=10)
plt.show() 출력
