Sometimes, we want to change the "tick frequency" on x or y axis in Python matplotlib.
In this article, we’ll look at how to change the "tick frequency" on x or y axis in Python matplotlib.
How to change the "tick frequency" on x or y axis in Python matplotlib?
To change the "tick frequency" on x or y axis in Python matplotlib, we can use the xticks
method.
For instance, we write
import numpy as np
import matplotlib.pyplot as plt
x = [0, 5, 9, 10, 15]
y = [0, 1, 2, 3, 4]
plt.plot(x, y)
plt.xticks(np.arange(min(x), max(x) + 1, 1.0))
plt.show()
to call plt.xticts
with np.arange(min(x), max(x) + 1, 1.0)
to space the ticks by differ by 1 and render the values from the lowest value in x
to the highest value in x
plus 1.
Conclusion
To change the "tick frequency" on x or y axis in Python matplotlib, we can use the xticks
method.