File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -297,11 +297,14 @@ def select_action(state):
297
297
episode_durations = []
298
298
299
299
300
- def plot_durations ():
300
+ def plot_durations (show_result = False ):
301
301
plt .figure (1 )
302
- plt .clf ()
303
302
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...' )
305
308
plt .xlabel ('Episode' )
306
309
plt .ylabel ('Duration' )
307
310
plt .plot (durations_t .numpy ())
@@ -312,9 +315,11 @@ def plot_durations():
312
315
plt .plot (means .numpy ())
313
316
314
317
plt .pause (0.001 ) # pause a bit so that plots are updated
315
- if is_ipython :
318
+ if is_ipython and not show_result :
316
319
display .display (plt .gcf ())
317
320
display .clear_output (wait = True )
321
+ else :
322
+ display .display (plt .gcf ())
318
323
319
324
320
325
######################################################################
@@ -443,11 +448,7 @@ def optimize_model():
443
448
break
444
449
445
450
print ('Complete' )
446
- durations_t = torch .tensor (episode_durations , dtype = torch .float )
447
- plt .title ('Result' )
448
- plt .xlabel ('Episode' )
449
- plt .ylabel ('Duration' )
450
- plt .plot (durations_t .numpy ())
451
+ plot_durations (show_result = True )
451
452
plt .ioff ()
452
453
plt .show ()
453
454
You can’t perform that action at this time.
0 commit comments