matplotlib/matplotlib — pull request #2002 by pelson (2013-05-14 15:18:05+00:00)
Title: Added support for providing 1 or 2 extra colours to the contour routines to easily specify the under and over colors.

I had a question from a colleague the other day about being able to specify the under and over colors of a contour.

The solution was:

```
import matplotlib.pyplot as plt
import numpy as np

data = np.arange(12).reshape(3, 4)

colors = ['red', 'yellow', 'pink', 'blue', 'black']
levels = [2, 4, 8, 10]

cs = plt.contourf(data, colors=colors[1:-1], levels=levels, extend='both')
plt.colorbar()
cs.cmap.set_under(colors[0])
cs.cmap.set_over(colors[-1])
cs.changed()

plt.show()
```

This PR makes the lines:

```
cs.cmap.set_under(colors[0])
cs.cmap.set_over(colors[-1])
cs.changed()
```

redundant.

If the user specifies ```n_colors = n_levels + n_extends``` then the appropriate ```set_under``` and ```set_over``` behaviour kicks in.

This change also fixes a bug with ```contour``` (i.e. not ```contourf```) and its handling of extend:

```
import matplotlib.pyplot as plt
import numpy as np

data = np.arange(12).reshape(3, 4)
colors = ['red', 'yellow', 'pink', 'blue', 'black']
levels = [2, 4, 8]
cs = plt.contour(data, colors=colors, levels=levels, extend='both')
plt.colorbar()
plt.show()
```
Results in:

```
...
File "matplotlib/colorbar.py", line 777, in _mesh
y = self._uniform_y(self._central_N())
File "matplotlib/colorbar.py", line 714, in _uniform_y
automin = automax = 1. / (N - 1.)
ZeroDivisionError: float division by zero
```

For the record, this PR *is* a functional change. The test results image before the code changes in this PR look like:

![before](https://f.cloud.github.com/assets/810663/502179/6dc38d74-bca9-11e2-9a6a-249a8afca1a3.png)