Reputation: 177
I am having two arrays each of the training and testing of the model. Now when I plot the lines in the same figure. The green line starts the label after the blue line on y-axis. Since y-axis is the accuracy I want it to be from 0 to 100 and both the lines should start from their respective points.
My code:
fig, plt.plot(train_acc)
plt.plot(test_acc)
plt.xlabel('Epochs',fontsize=15)
plt.ylabel('Accuracy',fontsize=15)
plt.xscale('Linear')
plt.xticks(np.arange(0,110,10),fontsize=12)
# plt.yticks(np.arange(0,105, step=5),fontsize=12)
plt.legend(['train', 'test'], loc='upper left')
plt.grid(True)
plt.show()
The weird plot:
train_acc = ('45.804', '67.724', '76.378', '82.516', '86.796', '90.08', '92.622', '94.486', '95.72', '96.618', '97.392', '97.876', '98.17', '98.374', '98.444', '98.952', '99.03', '99.22', '98.962', '99.236', '99.124', '98.934', '98.93', '99.354', '99.746', '99.944', '99.994', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0', '89.468', '93.626', '95.594', '97.194', '97.964', '98.194', '98.948', '98.992', '99.006', '98.604', '99.398', '99.452', '99.782', '99.698', '99.604', '99.888', '99.986', '99.998', '100.0', '99.452', '99.604', '99.986')
test_acc = ('59.63', '70.39', '76.63', '79.25', '79.91', '79.92', '80.57', '80.08', '81.7', '81.36', '81.66', '83.06', '81.86', '82.21', '82.29', '82.76', '82.66', '83.07', '82.4', '82.39', '81.48', '82.84', '83.08', '83.44', '84.29', '84.64', '85.07', '85.25', '85.41', '85.44', '85.46', '85.37', '85.32', '85.42', '85.41', '85.36', '85.41', '85.4', '85.39', '85.42', '85.5', '85.41', '85.45', '85.52', '85.56', '85.58', '85.52', '85.5', '85.54', '85.37', '85.44', '85.44', '85.39', '85.39', '85.35', '85.34', '85.48', '85.46', '85.35', '85.37', '85.34', '85.42', '85.46', '85.35', '85.46', '85.52', '85.29', '85.33', '85.18', '85.36', '85.41', '85.49', '85.3', '85.39', '85.26', '85.34', '85.36', '85.54', '80.32', '81.69', '81.41', '82.14', '82.67', '82.57', '83.58', '82.83', '83.75', '84.21', '84.41', '84.72', '84.95', '84.4', '84.18', '85.38', '85.74', '86.29', '86.4', '84.95', '84.21', '85.74')
Upvotes: 1
Views: 65
Reputation: 62403
train_acc = list(map(float, train_acc)) # convert strings to floats
test_acc = list(map(float, test_acc)) # convert strings to floats
plt.plot(train_acc, label='train')
plt.plot(test_acc, label='test')
plt.xlabel('Epochs',fontsize=15)
plt.ylabel('Accuracy',fontsize=15)
plt.xscale('Linear')
plt.xticks(np.arange(0,110,10),fontsize=12)
plt.ylim(0, 110) # set the range of the y-axis
plt.legend(loc='upper left')
plt.grid(True)
plt.show()
Upvotes: 1