My question is something related to: How to add title to Seaborn Heatmap color bar?
I have the following code:
import seaborn as sns
import pandas as pd
data = pd.DataFrame({'x':(1,2,3,4),'y':(1,2,3,4),'z':(1400,1500,2300,2000)})
sns.heatmap(data.pivot_table(index='y', columns='x', values='z'),
cbar_kws={'label': 'colorbar title'})
And I would like to add thousands separator to the color bar thickers, 2'250 or 2,250 for example. How can I accomplish this?
EDIT: I was redirected here: Formatting Numbers to have a comma on plt.colorbar() in Python Indeed it makes sense, but, how do I extract that from the seaborn heatmap?
EDIT 2 - Solution:
import seaborn as sns
import pandas as pd
from matplotlib.ticker import FuncFormatter
data = pd.DataFrame({'x':(1,2,3,4),'y':(1,2,3,4),'z':(1400,1500,2300,2000)})
comma_fmt = FuncFormatter(lambda x, p: format(int(x), ','))
sns.heatmap(data.pivot_table(index='y', columns='x', values='z'),
cbar_kws={'label': 'colorbar title','format':comma_fmt}).get_figure()