Code like this:
plt.ticklabel_format(style='plain', axis='x', useOffset=False)
plt.plot(range(1, 3), logger.acc)
plt.xlabel("Epochs")
plt.ylabel("Accuracy")
plt.show()
Produces a result like this:
I want the x axis to only have whole integer numbers. There should be a simple flag for this, but i can't find it.
Use xticks() method to show all the X-coordinates in the plot. Use yticks() method to show all the Y-coordinates in the plot. To display the figure, use show() method.
The xticks() function in pyplot module of the Matplotlib library is used to set x-axis values. List of xticks locations. Passing an empty list will remove all the xticks.
Using ticklabel_format() method with style='plain'. If a parameter is not set, the corresponding property of the formatter is left unchanged. Style='plain' turns off scientific notation.
To change the range of X and Y axes, we can use xlim() and ylim() methods.
Just use the following where you set the xticks
as the integer values generated by the range()
function. You can replace the numbers with whatever range you are plotting within
plt.xticks(range(1,3))
You may use a MultipleLocator
with the base set to 1
.
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
class logger():
acc = [ .26, .36]
plt.ticklabel_format(style='plain', axis='x', useOffset=False)
plt.plot(range(1, 3), logger.acc)
plt.gca().xaxis.set_major_locator(mticker.MultipleLocator(1))
plt.xlabel("Epochs")
plt.ylabel("Accuracy")
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With