我想用matplotlib的动画函数动态更新矩阵文本。但是我发现如果数据数组太大,动画会变得非常慢。有什么办法改进吗?在
from matplotlib import animation
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(10,20))
def updatefig(i):
plt.cla()
ax.grid()
data = np.random.rand(50,50)
ax.set_xticks(np.arange(data.shape[1]+1))
ax.set_yticks(np.arange(data.shape[0]+1))
for y in range(data.shape[0]):
for x in range(data.shape[1]):
plt.text(x + 0.5 , y + 0.5, '%.1f' % data[y, x],horizontalalignment='center',verticalalignment='center',color='b',size = 6)
plt.draw()
anim = animation.FuncAnimation(fig, updatefig,interval=50)
plt.show()
实际上,我想用下面的链接这样的数据值创建一个heatmmap图。但是使用注释是我唯一能理解的方法。 Heamap with values
通过导入seaborn模块找到解决方法。 但如何避免图形不断闪烁呢
^{1}$相关问题 更多 >
编程相关推荐