[BUG]: Weirdness with `center` when using non-default colormaps
See original GitHub issueI have code that looks like this:
import matplotlib
import seaborn as sns
A = np.eye(2)
fig, ax = plt.subplots(figsize=(10,10))
cmap = matplotlib.colors.ListedColormap(["white", "black"])
ax = sns.heatmap(A, cmap=cmap, ax=ax, center=0, cbar=False)
This code produces a heatmap that looks like this:
However, when I change center
to None
, I correctly get the heatmap that I want:
And, interestingly, when center
is 0
and cmap = matplotlib.colors.ListedColormap(["white", "white", "black"])
, I get the correct heatmap again.
I’m not familiar enough with the heatmap API to know whether this is a bug, but it seems like it might be?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
row_colors/col_colors not working when a non-default ...
Basically, I am trying to compute a clustermap using both row_colors and a colorbar normalization which is different from the default one. Let's ......
Read more >Problems Repaired for Version 6.1
There is a bug if a 2D Bridge has 100 or more cells/faces along the centerline of the bridge. This may show up...
Read more >View and set current colormap - MATLAB colormap - MathWorks
This MATLAB function sets the colormap for the current figure to one of the predefined colormaps.
Read more >Using MATLAB Graphics
bugs @mathworks.com ... Indexed Color Surfaces — Direct and Scaled Colormapping 11-16 ... Factors to consider when using a nondefault print driver,.
Read more >What's new in each version — seaborn 0.11.2 documentation
Fix In histplot() , fixed a bug where using shrink with non-discrete bins shifted ... this may cause plots to look different with...
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 FreeTop 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
Top GitHub Comments
Good to know. So I was wrong, there isn’t a problem interpolating a discrete colormap (good!) and the “weirdness” arises from using
center
with binary (i.e. 0, and 1) data.I think we can consider this resolved, but @loftusa if you think better documentation of the
center
parameter would have avoided this confusion I’d be happy to consider them.Here is some example code showing how
center
works. It can work perfectly with a bicolored colormap, although if can be harder to understand.With only two colors:
So, setting
center=0
gets what you asked for.