sns.histplot([1, 2, 3], binwidth=7) crashes with
"ValueError: bins must be positive, when an integer"
It is related to #2721, which is marked as solved, but the error also happens in the dev version.
The cause seems to be line 136 in counting.py with bins = int(round((stop - start) / binwidth)), setting it to 0 for small ranges. Changing this to bins = max(1, int(round((stop - start) / binwidth))) would probably solve it adequately.
(The code also has problems when binwidth=0 (division by zero) or negative (this makes bins negative, which causes numpy to protest)).
By the way, binwidth is ignored when discrete=True. As an example, sns.histplot(titanic[titanic['who'] == 'woman'], x='age', binwidth=5) has some bins with 5 and others with 6 ages. Of course, people who really care can provide their own custom bin edges.
sns.histplot([1, 2, 3], binwidth=7)crashes with"ValueError:
binsmust be positive, when an integer"It is related to #2721, which is marked as solved, but the error also happens in the dev version.
The cause seems to be line 136 in counting.py with
bins = int(round((stop - start) / binwidth)), setting it to0for small ranges. Changing this tobins = max(1, int(round((stop - start) / binwidth)))would probably solve it adequately.(The code also has problems when
binwidth=0(division by zero) or negative (this makesbinsnegative, which causes numpy to protest)).By the way,
binwidthis ignored whendiscrete=True. As an example,sns.histplot(titanic[titanic['who'] == 'woman'], x='age', binwidth=5)has some bins with 5 and others with 6 ages. Of course, people who really care can provide their own custom bin edges.