5

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.pyplot as plt

plt.matshow(np.array(([30000,8000],[12000,25000])))
plt.colorbar()
Jay
  • 53
  • 3

1 Answers1

7

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()

enter image description here

jedwards
  • 29,432
  • 3
  • 65
  • 92