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

后端 未结 7 1602
野性不改
野性不改 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:19

    Short answer without importing matplotlib as mpl

    plt.gca().yaxis.set_major_formatter(plt.matplotlib.ticker.StrMethodFormatter('{x:,.0f}'))
    

    Modified from @AlexG's answer

提交回复
热议问题