When using seaborn.heatmap() to plot percentages, the heatmap is correctly annotated to show percentages, i.e., it multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign. However, the format is not applied to the colorbar ticks, which are shown fixed format.
Example:
import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
sns.heatmap(uniform_data, annot=True, fmt='.0%')

They're not expected to be; the annotations are just text added to the figure.
Maybe I am missing something, but are there cases in which it is useful to have the annotations and the colorbar in different formats? As far as I can tel,l they convey the same information, so showing different formats does not seem to be useful.
Just for compleness, one can achieve the behaviour I expected with some extra code:
from matplotlib.ticker import funcformatter
import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
fmt = lambda x,pos: '{:.0%}'.format(x)
sns.heatmap(uniform_data, annot=true, fmt='.0%',
cbar_kws={'format': funcformatter(fmt)})
Maybe I am missing something, but are there cases in which it is useful to have the annotations and the colorbar in different formats? As far as I can tel,l they convey the same information, so showing different formats does not seem to be useful.
Just for compleness, one can achieve the behaviour I expected with some extra code:
from matplotlib.ticker import funcformatter import numpy as np; np.random.seed(0) import seaborn as sns; sns.set() uniform_data = np.random.rand(10, 12) fmt = lambda x,pos: '{:.0%}'.format(x) sns.heatmap(uniform_data, annot=true, fmt='.0%', cbar_kws={'format': funcformatter(fmt)})
Slight correction to this code to function:
from matplotlib.ticker import FuncFormatter
import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
fmt = lambda x,pos: '{:.0%}'.format(x)
sns.heatmap(directionality, annot=True, fmt='.0%',
cbar_kws={'format': FuncFormatter(fmt)})
Most helpful comment
Maybe I am missing something, but are there cases in which it is useful to have the annotations and the colorbar in different formats? As far as I can tel,l they convey the same information, so showing different formats does not seem to be useful.
Just for compleness, one can achieve the behaviour I expected with some extra code: