Skip to content

Fix a display bug which cannot update figure correctly #2144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 14, 2022
17 changes: 12 additions & 5 deletions intermediate_source/reinforcement_q_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,14 @@ def select_action(state):
episode_durations = []


def plot_durations():
def plot_durations(show_result=False):
plt.figure(1)
plt.clf()
durations_t = torch.tensor(episode_durations, dtype=torch.float)
plt.title('Training...')
if show_result:
plt.title('Result')
else:
plt.clf()
plt.title('Training...')
plt.xlabel('Episode')
plt.ylabel('Duration')
plt.plot(durations_t.numpy())
Expand All @@ -313,8 +316,11 @@ def plot_durations():

plt.pause(0.001) # pause a bit so that plots are updated
if is_ipython:
display.clear_output(wait=True)
display.display(plt.gcf())
if not show_result:
display.display(plt.gcf())
display.clear_output(wait=True)
else:
display.display(plt.gcf())


######################################################################
Expand Down Expand Up @@ -443,6 +449,7 @@ def optimize_model():
break

print('Complete')
plot_durations(show_result=True)
plt.ioff()
plt.show()

Expand Down