Matplotlib: show labels for minor ticks also

前端 未结 3 936
野趣味
野趣味 2020-12-09 20:21

In matplotlib, when I use a log scale on one axis, it might happen that that axis will have no major ticks, only minor

3条回答
  •  时光取名叫无心
    2020-12-09 21:08

    You can use set_minor_tickformatter on the corresponding axis:

    from matplotlib import pyplot as plt
    from matplotlib.ticker import FormatStrFormatter
    
    axes = plt.subplot(111)
    axes.loglog([3,4,7], [2,3,4])
    axes.xaxis.set_minor_formatter(FormatStrFormatter("%.2f"))
    plt.xlim(1.8, 9.2)
    plt.show()
    

    enter image description here

提交回复
热议问题