python
type_error
ai_generated
true
TypeError: 'bins' must be an integer, a sequence of scalars, or a string, not <class 'list'> of strings.
ID: python/matplotlib-histogram-bins-error
80%Fix Rate
85%Confidence
0Evidence
2024-05-25First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
Root Cause
Passing a list of strings as bins to plt.hist(), which expects numeric bins or a single string method (like 'auto', 'fd').
generic中文
向plt.hist()传递了字符串列表作为bins参数,但该参数需要数值型bins或单个字符串方法(如'auto'、'fd')。
Workarounds
-
95% success Use an integer for the number of bins
plt.hist(data, bins=20)
-
90% success Use a sequence of bin edges as numbers
plt.hist(data, bins=[0, 10, 20, 30])
Dead Ends
Common approaches that don't work:
-
Using a list of integers but with mixed types
80% fail
Bins must be numeric; mixed types cause conversion errors.
-
Passing a single string like 'auto' but in a list
90% fail
A list of one string is still a list, not a valid bins argument.