0

场景
我想以 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()
4

1 回答 1

0

解决方案(根据评论)被发现清除轴:

# Update the new Q-Value
if 'previous' in globals(): 
    previous.axes.clear()
previous = draw_Table(Q)

[这已从问题中编辑为答案]

于 2018-09-07T20:44:17.710 回答