Код: Выделить всё
# main_code.py
from helper import plot
# ... bunch of other code ...
def update_matplot():
plot_scores = [] # Scores for each game
plot_mean_scores = [] # Average scores over a rolling window
# ... bunch of other code ...
plot_scores.append(score)
total_score += score
mean_score = total_score / agent.n_games
plot_mean_scores.append(mean_score)
plot(plot_scores, plot_mean_scores)
Вот helper.py с функциейplot():
Код: Выделить всё
import matplotlib.pyplot as plt
from IPython import display
plt.ion()
def plot(scores, mean_scores):
display.clear_output(wait=True)
display.display(plt.gcf())
plt.clf()
plt.title('Game Data')
plt.xlabel('Number of games')
plt.ylabel('Score')
plt.plot(scores)
plt.plot(mean_scores)
plt.ylim(ymin=0)
plt.text(len(scores)-1, scores[-1], str(scores[-1]))
plt.text(len(mean_scores)-1, mean_scores[-1], str(mean_scores[-1]))
plt.show()
plt.pause(0.1)
Код: Выделить всё
# main_code.py
from helper import new_plot
# ... bunch of other code ...
def update_matplot():
plot_scores = [] # Scores for each game
plot_mean_scores = [] # Average scores over a rolling window
plot_times = [] # Time for each game
plot_mean_times = [] # Average times over a rolling window
# ... bunch of other code ...
plot_scores.append(score)
total_score += score
mean_score = total_score / agent.n_games
plot_mean_scores.append(mean_score)
# New game time code:
plot_times.append(single_game_time)
mean_time = total_game_times / num_games
plot_mean_times.append(mean_time)
# New function call
new_plot(plot_scores, plot_mean_scores, plot_times, plot_mean_times)
Код: Выделить всё
import matplotlib.pyplot as plt
from IPython import display
plt.ion()
def new_plot(scores, mean_scores, times, mean_times):
#
# Help!! :)
#
Подробнее здесь: https://stackoverflow.com/questions/793 ... nt-scale-o