Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong ticks on heatmap colorbar when using fmt=.0% #917

Closed
rrbarbosa opened this issue May 4, 2016 · 3 comments
Closed

Wrong ticks on heatmap colorbar when using fmt=.0% #917

rrbarbosa opened this issue May 4, 2016 · 3 comments

Comments

@rrbarbosa
Copy link

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%')

figure_1

@mwaskom
Copy link
Owner

mwaskom commented May 4, 2016

They're not expected to be; the annotations are just text added to the figure.

@mwaskom mwaskom closed this as completed May 4, 2016
@rrbarbosa
Copy link
Author

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)})

@CharlesGaydon
Copy link

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)})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants