0

If in seaborn.heatmap() I use annot=True, fmt='g', I get both (mixed) int and float values in annotations on a heatmap. Is there an easy way to round or truncate the float values in the annotations, so that I get int values only? Thanks.

I tried fmt='g', 'fmt='d', but it did not work.

devedzic
  • 11
  • 2
  • can you provide a minimal reproducible example? – mozway Nov 12 '22 at 17:49
  • Thanks, guys. I know I should have provided a reproducible example, but the example I have is too complex and requires working on it to get to a minimal version - I thought the thing that I asked was easy for experts even without a minimal example. @JohanC: `fmt='%.0f'` doesn't work either, I still get mixed int and float values. – devedzic Nov 12 '22 at 22:39
  • And, yes, I tried it in both Jupyter Notebook and DataSpell. – devedzic Nov 12 '22 at 22:40
  • Well, you really need a reproducible example. If your data is in a dataframe, and your values aren't strings, `fmt='.0f'` (without the `%`) should work. Couldn't you create a very simple reproducible example (e.g. just 4 values)? Like `sns.heatmap(data=[[1, 2], [4.5, 5.5]], annot=True, fmt='.0f')` shows all values rounded to integers. Do your data contain something else? – JohanC Nov 12 '22 at 22:52
  • @JohanC: That's it, thank you !!! `fmt='.0f'` (without the `%`) works :) As for a minimal reproducible example, I was going to provide it from my own real-world example (which was more complex and that's why I didn't provide it in my original question), but luckily you figured it out yourself what the problem was. Thanks again. – devedzic Nov 13 '22 at 09:46

0 Answers0