# ValueError: Number of contour levels must be at least 2, got 1.

- **ID:** `python/matplotlib-contour-levels-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Passing a single value for levels parameter in contour/contourf, which requires at least two levels to draw contours.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.7 | active | — | — |
| 3.8 | active | — | — |

## Workarounds

1. **Provide at least two levels as an array** (95% success)
   ```
   plt.contour(X, Y, Z, levels=[0, 1, 2])
   ```
2. **Use an integer to specify the number of automatically chosen levels** (90% success)
   ```
   plt.contour(X, Y, Z, levels=10)  # at least 2
   ```

## Dead Ends

- **Using a negative number of levels** — Levels must be positive integers or an array; negative numbers raise a different error. (90% fail)
- **Setting levels as a string like 'auto'** — In some versions, 'auto' is not a valid input; it must be a number or array. (70% fail)
