how to turn on minor ticks only on y axis matplotlib


Question

How can I turn the minor ticks only on y axis on a linear vs linear plot?

When I use the function minor_ticks_on to turn minor ticks on, they appear on both x and y axis.

1
59
4/16/2019 9:58:53 AM

Accepted Answer

Nevermind, I figured it out.

ax.tick_params(axis='x', which='minor', bottom=False)
46
2/7/2019 9:32:53 AM

Here's another way I found in the matplotlib documentation:

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.ticker import MultipleLocator

a = np.arange(100)
ml = MultipleLocator(5)
plt.plot(a)
plt.axes().yaxis.set_minor_locator(ml)
plt.show()

This will place minor ticks on only the y-axis, since minor ticks are off by default.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon