python
runtime_error
ai_generated
true
ValueError: xlim must be a 2-element sequence of numbers, got [0, 10, 20]
ID: python/matplotlib-axes-limits-error
80%Fix Rate
84%Confidence
0Evidence
2024-04-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
Root Cause
Passing a list with more than two elements to set_xlim() or xlim parameter.
generic中文
向set_xlim()或xlim参数传递了包含两个以上元素的列表。
Workarounds
-
95% success Use a two-element sequence
ax.set_xlim([0, 10]) # or (0, 10)
-
90% success Set min and max separately
ax.set_xlim(left=0, right=10)
Dead Ends
Common approaches that don't work:
-
Passing a tuple of three numbers
90% fail
A tuple with three elements also fails; only two-element sequences are allowed.
-
Using xlim=(0,10,20) as keyword argument
85% fail
Same issue; xlim expects exactly two values.