import matplotlib.pyplot as plt
import pickle
import numpy as np

handle1 = open('history_overfit.pickle', 'rb') 
history1 = pickle.load(handle1)

handle2 = open('history.pickle', 'rb') 
history2 = pickle.load(handle2)

plt.plot( np.linspace(0,19,20), history1['accuracy'], label='Train accuracy, dropout = 0.2', color='tab:blue' )
plt.plot( np.linspace(0,19,20), history1['val_accuracy'], label='Validation accuracy, dropout = 0.2', linestyle='--', color='tab:blue' )
plt.plot( np.linspace(0,19,20), history2['accuracy'], label='Train accuracy, dropout = 0.5', color='tab:orange' )
plt.plot( np.linspace(0,19,20), history2['val_accuracy'], label='Validation accuracy, dropout = 0.5', linestyle='--', color='tab:orange' )
plt.xticks(np.linspace(0,19,20))
plt.ylim(0.0,1.0)
plt.legend(loc='best')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.savefig('acc_vs_epoch.png', dpi=100)

plt.gcf().clear()

plt.plot( np.linspace(0,19,20), history1['loss'], label='Train loss, dropout = 0.2', color='tab:blue' )
plt.plot( np.linspace(0,19,20), history1['val_loss'], label='Validation loss, dropout = 0.2', linestyle='--', color='tab:blue' )
plt.plot( np.linspace(0,19,20), history2['loss'], label='Train loss, dropout = 0.5', color='tab:orange' )
plt.plot( np.linspace(0,19,20), history2['val_loss'], label='Validation loss, dropout = 0.5', linestyle='--', color='tab:orange' )
plt.xticks( np.linspace(0,19,20) )
plt.ylim(0.0,1.0)
plt.legend(loc='best')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.xticks(np.linspace(1,21,21))
plt.savefig('loss_vs_epoch.png', dpi=100)