histplot 2D ignores hue_norm argument
See original GitHub issueDescription
If I understand correctly, when plotting a 2D histogram with histplot
, the hue_norm
argument should allow setting the values corresponding to data values corresponding to the extremes of the colormap, or a normalization object from matplotlib.colors
such as LogNorm
.
However, it seems that the hue_norm
argument is being ignored. Even providing objects of some unreasonable type the same plot is produced, with no errors or complains.
Versions
seaborn 0.11.1 matplotlib 3.4.1
Example
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
x = np.random.randn(1000)
y = np.random.randn(1000)
fig, axs = plt.subplots(ncols=4, figsize=(16,3))
sns.histplot(x=x, y=y, ax=axs[0], cbar=True)
sns.histplot(x=x, y=y, ax=axs[1], cbar=True, hue_norm=(6, 10))
sns.histplot(x=x, y=y, ax=axs[2], cbar=True, hue_norm=LogNorm())
sns.histplot(x=x, y=y, ax=axs[3], cbar=True, hue_norm='I would expect strings to crash')
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
seaborn.histplot — seaborn 0.12.1 documentation - PyData |
Generic bin parameter that can be the name of a reference rule, the number of bins, or the breaks of the bins. ......
Read more >matplotlib.pyplot.hist2d — Matplotlib 3.1.2 documentation
Rendering the histogram with a logarithmic color scale is accomplished by passing a colors. LogNorm instance to the norm keyword argument.
Read more >MATLAB hist3 - Bivariate histogram plot - MathWorks
Similarly, hist3 ignores Inf and –Inf values unless you explicitly specify Inf or –Inf as a bin edge by using the edges input...
Read more >2D Plots Reporting - ClearML
To report more than one series on the same plot, use same the title argument. For different plots, use different title arguments. Specify...
Read more >Chapter: Histograms - ROOT
Making a projection from a 2-D or 3-D histogram. Reading a histogram from a ... The second parameter (1000) indicates how many random...
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
I suspected that. Seems totally reasonable to me! 👌
Fair enough! I guess it would have saved me (and you, sorry for the noise again) some time. But I totally see your point, so I leave it at your judgement. I would not mind having an example of a 2D histogram with log color scale, but I agree that it might be left for an answer at stackoverflow.
You’re right,
sns.histplot(x=x, y=y, cbar=True, norm=LogNorm(), vmin=None, vmax=None)
works. The thing is that at first I had only triedsns.histplot(x=x, y=y, cbar=True, norm=LogNorm())
-using the same data from the first message- but it fails because it conflicts withvmin
andvmax
set byhistplot
, not sure why I didn’t try to set the limits to None.It also throws a
MatplotlibDeprecationWarning
about getting bothnorm
andvmax
/vmin
parameters simultaneously, and threatens to become an error at v3.5.In any case, unless you think something needs to be done about that
norm
andvmin
/vmax
conflict, I would say you can close the issue. Thanks a lot for the patience and clarity! 🙏 (and for the awesome library, of course! 😉 )(Sorry for the silence, busy days)
The option I can think of would be to avoid passing
vmin
andvmax
to pcolormesh whennorm
is present/not None. Then, it would be up to the user to manage same/different color norm. The ugly part is that the user providing bothvmin
/vmax
andnorm
at the same would imply either raising an error (from seaborn or matplotlib) or ignoring either the parameters. And also, I guess that would require adding norm as an explicit parameter for seaborn, as it would modify/interact with other explicit parametersTrying to set
vmin
/vmax
to theNormalize
subclass would work forLogNorm
but is way less robust. Not all the subclasses in matplotlib.colors have these attributes.Tot convinced by any option… 🤔 Do you have any approach in mind?