Escenario 我想更新时间延迟为1秒的热图值。目标是代表强化学习问题中Q表的演变。
码 Q最初是一个全零的pandas DataFrame 创建seaborn热图的功能:
# Helper functions to draw, update and get values of the table
def draw_Table(Q):
table = sns.heatmap(Q, cmap='Blues', annot=True, linewidths=.5, cbar=False,
linecolor='black', square=True).set_title('Q-Table')
return table
这是主要功能:
plt.ion()
plt.figure(figsize = (10,10))
for i in range(EPISODES):
print('Episode [{}/{}]'.format(i,EPISODES))
print('Current Q-Table')
# Some code that updates the values of Q
# Update the new Q-Value
if 'previous' in globals(): del previous
previous = draw_Table(Q)
plt.pause(1)
plt.ioff()
plt.show()
发现解决方案(根据评论)清除轴:
# Update the new Q-Value
if 'previous' in globals():
previous.axes.clear()
previous = draw_Table(Q)
[这被编辑成问题的答案]