2

I have a dataframe that contains percentages. If I use seaborn to make a clusterplot somehow the number 100 is plotted as 1+e01.

Is there any way to avoid this?

I tried rounding the percentages before plotting them, but that does not affect the plot.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Private
  • 2,626
  • 1
  • 22
  • 39

1 Answers1

6

Use fmt="d", as in this example:

import seaborn as sns
sns.set()

flights_long = sns.load_dataset("flights")
flights = flights_long.pivot("month", "year", "passengers")
flights = flights.reindex(flights_long.iloc[:12].month)

sns.heatmap(flights, annot=True, fmt="d")

enter image description here

fmt is a parameter to heatmap but additional clustermap kwargs are passed through to the main heatmap.

mwaskom
  • 46,693
  • 16
  • 125
  • 127
  • 1
    Is there another way than using `"d"`? I'm having trouble with numpy's float arrays. I want to avoid using `array.astype(int)` if possbile, because I want `nan` values to not be displayed in the heat map. EDIT: Ok, I found out that [`"g"`](https://stackoverflow.com/a/29648332/7669319) works – Felix Jassler Feb 14 '22 at 09:34