1

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()

accuracy figure

1 Answer 1

1

Try the below:

import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter

acc = history.history['accuracy']

fig, ax = plt.subplots()
plt.plot([i for i in range(len(acc))], acc)
ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
plt.show()

But you may see multiple ticks with the same value. Alternatively or in addition you can use the below to limit the ticks to what you want to be shown:

ax.set_yticks([0.8, 0.9, 1.0])
Sign up to request clarification or add additional context in comments.

2 Comments

I tried both ways but nothing changed in the graph
Sorry, for a second I got confused as to what exactly the problem is. I edited my answer and hepfully this will solve your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.