场景
我想以 1 秒的时间延迟更新热图的值。目标是表示强化学习问题中 Q 表的演变。
代码Q 最初
是用于创建 seaborn 热图
的全零 pandas DatraFrame函数:
# 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()