Escenario
I want to update the values of a heatmap with a time delay of 1 seconds. The objective is represent the evolution of the Q-Table in a reinforcement learning problem.
Error
The problem is that the heatmap figure is being updated but the values are kept intead of replaced.
Code
Q is intially an all-zeros pandas DatraFrame
Function to create seaborn heatmap:
# 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
Here is the main functionality:
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()