matplotlib绘制热力图动画 |
您所在的位置:网站首页 › 热力图动画 › matplotlib绘制热力图动画 |
import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.animation import FuncAnimationfrom mpl_toolkits.axes_grid1 import make_axes_locatable fig, ax = plt.subplots()div = make_axes_locatable(ax)cax = div.append_axes('right', '5%', '5%') num_frames = 50row, col = 101, 101data = np.random.rand(num_frames, row, col)img = ax.imshow(np.zeros((row, col)), cmap=plt.cm.hot, vmin=0, vmax=1.0, origin='lower')cbr = fig.colorbar(img, cax=cax) def update(i): X = data[i] vmax = np.max(X) vmin = np.min(X) img.set_data(X) img.set_clim(vmin, vmax) ani = FuncAnimation(fig, update, frames=num_frames)plt.show() |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |