How do I format axis number format to thousands with a comma in matplotlib?

后端 未结 7 1604
野性不改
野性不改 2020-11-29 20:48

How can I change the format of the numbers in the x-axis to be like 10,000 instead of 10000? Ideally, I would just like to do something like this:<

7条回答
  •  青春惊慌失措
    2020-11-29 21:39

    I always find myself on this same page everytime I try to do this. Sure, the other answers get the job done, but aren't easy to remember for next time! ex: import ticker and use lambda, custom def, etc.

    Here's a simple solution if you have an axes named ax:

    ax.set_yticklabels(['{:,}'.format(int(x)) for x in ax.get_yticks().tolist()])
    

提交回复
热议问题