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

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

    If you like it hacky and short you can also just update the labels

    def update_xlabels(ax):
        xlabels = [format(label, ',.0f') for label in ax.get_xticks()]
        ax.set_xticklabels(xlabels)
    
    update_xlabels(ax)
    update_xlabels(ax2)
    

提交回复
热议问题