question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heatmap: Specifying number of ticks or tick locations in cmap

See original GitHub issue

First off, thanks so much @mwaskom for this great library. We use it constantly at my work place!

Q. I could not find an option to change the ticks locations (or the number of ticks) for the colormap in a heatmap. That is, I’m not talking about the x or y axis, but the ticks in the cmap itself.

Any suggestions on how to do it?

E.g. for:

# Draw the heatmap with the mask and correct aspect ratio
g = sns.heatmap(corr, mask=mask, cmap=cmap, vmax=1,
                square=True, linewidths=.5, cbar_kws={"shrink": .9}, ax=ax)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
mwaskomcommented, Sep 29, 2016

You can use the ticks colorbar keyword argument (requires version 0.7.1+):

x = np.random.rand(10, 10)
sns.heatmap(x, cbar_kws=dict(ticks=[.2, .5, .6]))

image

2reactions
nightm4re94commented, May 5, 2020

I have the same issue as @andt88 : With a logarithmic norm, the “ticks” keyword gets ignored entirely. This is the code that produces my heatmap:

log_norm = LogNorm(vmin=1, vmax=1e7)
hm = sb.heatmap(data=matrix_df, xticklabels=10, yticklabels=10, cmap=heatmap_colors, norm=log_norm, cbar=True, cbar_kws={"label": lbl_cycle_count, "ticks": None, "shrink": 1}, vmin=1, vmax=1e7)
hm.set_yticklabels(hm.get_yticklabels(), rotation=0)
hm.set_xticklabels(hm.get_xticklabels(), rotation=90)

But in the result, the ticks of the color bar are shown logarithmically.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Seaborn heatmap, custom tick values - Stack Overflow
My solution is a little bit ugly but it works for me. Suppose your depth data is in depth_list and num_ticks is the...
Read more >
seaborn.heatmap — seaborn 0.12.1 documentation
The value at which to center the colormap when plotting divergent data. Using this parameter will change the default cmap if none is...
Read more >
All About Heatmaps - Towards Data Science
For numeric axis variables, If there are few bins, it is acceptable to keep tick marks on each bin. However, plotting tick marks...
Read more >
How to control heatmap colorbar ticks? - HoloViz Discourse
I would like to have a heatmap which meets the following requirements: Specify limits and colors within the limits. Ticks on the colorbar ......
Read more >
Colorbar Tick Labelling — Matplotlib 3.4.3 documentation
... vertical colorbar') # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar(cax, ticks=[-1, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found