151

I'm creating a heatmap from a pandas pivot_table as below:

table2 = pd.pivot_table(df,values='control',columns='Year',index='Region',aggfunc=np.sum)
sns.heatmap(table2,annot=True,cmap='Blues')

It creates a heat map as shown below. You can see the numbers are not huge (max 750), but it's showing them in scientific notation. If I view the table itself this is not the case. Any idea on how I could get it to show the numbers in plain notation?

Heatmap

rene
  • 39,748
  • 78
  • 111
  • 142
cigrainger
  • 1,736
  • 2
  • 13
  • 11

2 Answers2

269

According to the docs, the param fmt='.2g' is being applied because you've set annot=True so you can modify the format being applied to:

sns.heatmap(table2,annot=True,cmap='Blues', fmt='g')
zabop
  • 5,493
  • 3
  • 23
  • 56
EdChum
  • 339,461
  • 188
  • 752
  • 538
  • 25
    You can also use `fmt='d'` if your values are integers like this: `sns.heatmap(table2, annot=True, cmap='Blues', fmt='d')` – tsveti_iko Jul 24 '19 at 09:50
  • 2
    For floats with two decimal places, it's `.2f`. See https://docs.python.org/3/library/string.html?highlight=string#formatspec for more options. – Suzana Jan 13 '21 at 15:25
4

According to the docs, the parameter fmt is set to .2g when annot=True. So, for example, if your data is float, you can use:

sns.heatmap(table2, annot=True, cmap='Blues', fmt='.3g')

By that, you're telling python to show 3 significant figures. To understand the "fmt" better, check out this answer: https://stackoverflow.com/a/65020192/4529605

Gobryas
  • 161
  • 7