格式化数字在Python中的plt.colorbar()上有一个逗号
问题描述:
我想格式化我的颜色条,数字用逗号格式化。任何帮助将不胜感激格式化数字在Python中的plt.colorbar()上有一个逗号
import numpy as np
import matplotlib.pyplot as plt
plt.matshow(np.array(([30000,8000],[12000,25000])))
plt.colorbar()
答
您可以创建并指定一个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()
https://preinventedwheel.com/matplotlib-thousands-separator-1-step-指导/ –
FWIW,对于有6位代表的新用户,这是一款出色的MCVE。谢谢。 – jedwards