how to turn on minor ticks only on y axis matplotlib

前端 未结 5 1828
故里飘歌
故里飘歌 2020-12-07 17:08

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

5条回答
  •  庸人自扰
    2020-12-07 18:00

    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.

提交回复
热议问题