I am plotting the accuracy and loss figures. I am getting the following plot that represents 3 places after 0 like 0.XXX I aim to present only one like 0.X
how can I fix this
acc = history.history['accuracy']
acc_val = history.history['val_accuracy']
epochs = range(len(acc))
plt.title('Training and Validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('accuracy')
plt.legend()
plt.show()
CodePudding user response:
Your problem can be solved by rounding the accuracy values. You can do this this simply with the built-in round()
function:
acc = [round(i, 1) for i in history.history['accuracy']]
or using the map()
function:
acc = list(map(lambda x: round(x, 1), history.history['accuracy']))
CodePudding user response:
I think you are looking for this: https://matplotlib.org/stable/api/ticker_api.html
ax.xaxis.set_major_formatter(FormatStrFormatter('%.3f'))
Edit: regarding to your example, to get axis take a loog here: How to get a matplotlib Axes instance to plot to?
ax = plt.gca()