Formatting Numbers to have a comma on plt.colorbar() in Python

前端 未结 1 1363
耶瑟儿~
耶瑟儿~ 2021-01-20 09:48

I am trying to format my colorbar such the numbers are formatted with commas. Any help would be greatly appreciated

import numpy as np
import matplotlib.pypl         


        
相关标签:
1条回答
  • 2021-01-20 10:26

    You can create and specify a custom formatter:

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.ticker import FuncFormatter
    
    comma_fmt = FuncFormatter(lambda x, p: format(int(x), ','))
    
    plt.matshow(np.array(([30000,8000],[12000,25000])))
    plt.colorbar(format=comma_fmt)
    
    plt.show()
    

    0 讨论(0)
提交回复
热议问题