Heatmaps can have too long numeric labels
See original GitHub issueOften times, I have heatmaps like this:
I’d like for the numeric labels to be shorter. I eventually found a solution through this SO answer after looking at the source for keywords to google. This solution is nowhere as clean as I’d like.
d = [{'p1': p1, 'p2': p2, 'error': np.random.rand()}
for p1 in np.logspace(0, 1, num=5)
for p2 in np.logspace(0, 3, num=5)]
df = pd.DataFrame(d)
df = df.pivot(values='error', index='p1', columns='p2')
ax = sns.heatmap(df)
# format text labels
fmt = '{:0.2f}'
xticklabels = []
for item in ax.get_xticklabels():
item.set_text(fmt.format(float(item.get_text())))
xticklabels += [item]
yticklabels = []
for item in ax.get_yticklabels():
item.set_text(fmt.format(float(item.get_text())))
yticklabels += [item]
ax.set_xticklabels(xticklabels)
ax.set_yticklabels(yticklabels)
plt.show()
…which produces this plot:
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Round decimal places seaborn heatmap labels - Stack Overflow
I have a heat map that gets its labels ...
Read more >A Complete Guide to Heatmaps | Tutorial by Chartio
Heatmaps take the form of a grid of colored squares, where colors correspond with cell value. This article will show you how to...
Read more >How to include labels in sns heatmap
I got your problem like this way: You want to show labels on the x and y-axis on the seaborn heatmap. So for...
Read more >How can I modify the X and Y axis tick labels for a Heatmap ...
Direct link to this answer I understand that you are trying to change the displayed tick labels on the X and Y axis...
Read more >Using heat maps - Amazon QuickSight - AWS Documentation
Work with the heat map visual type in Amazon QuickSight. ... Heat maps can also be used to show the count of values...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@stsievert to really make this work with seaborn I had to overwrite the current
FixedFormatterlikeand then it worked.
There’s a number of ways to control this sort of thing. The matplotlib solution would be to use a tick formatter. Or you could do