Python matplotlib restrict to integer tick locations

后端 未结 3 1361
我寻月下人不归
我寻月下人不归 2020-11-29 11:15

Quite often I want to make a bar chart of counts. If the counts are low I often get major and/or minor tick locations that are not integers. How can I prevent this? It makes

3条回答
  •  无人及你
    2020-11-29 11:38

    You can use the MaxNLocator method, like so:

        from pylab import MaxNLocator
    
        ya = axes.get_yaxis()
        ya.set_major_locator(MaxNLocator(integer=True))
    

提交回复
热议问题