Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c19831

Browse files
Yichi-Lionel-CheungSvetlana Karslioglu
andauthored
Fix a display bug which cannot update figure correctly (#2144)
* Fix a display bug which cannot update figure correctly. * Modify plot_durations * fix a bug when not using ipython Co-authored-by: Svetlana Karslioglu <[email protected]>
1 parent 3a458e7 commit 3c19831

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

intermediate_source/reinforcement_q_learning.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,14 @@ def select_action(state):
297297
episode_durations = []
298298

299299

300-
def plot_durations():
300+
def plot_durations(show_result=False):
301301
plt.figure(1)
302-
plt.clf()
303302
durations_t = torch.tensor(episode_durations, dtype=torch.float)
304-
plt.title('Training...')
303+
if show_result:
304+
plt.title('Result')
305+
else:
306+
plt.clf()
307+
plt.title('Training...')
305308
plt.xlabel('Episode')
306309
plt.ylabel('Duration')
307310
plt.plot(durations_t.numpy())
@@ -313,8 +316,11 @@ def plot_durations():
313316

314317
plt.pause(0.001) # pause a bit so that plots are updated
315318
if is_ipython:
316-
display.clear_output(wait=True)
317-
display.display(plt.gcf())
319+
if not show_result:
320+
display.display(plt.gcf())
321+
display.clear_output(wait=True)
322+
else:
323+
display.display(plt.gcf())
318324

319325

320326
######################################################################
@@ -443,6 +449,7 @@ def optimize_model():
443449
break
444450

445451
print('Complete')
452+
plot_durations(show_result=True)
446453
plt.ioff()
447454
plt.show()
448455

0 commit comments

Comments
 (0)