matplotlib/matplotlib — pull request #3589 by jakevdp (2014-09-29 01:54:00+00:00)
Title: ENH: add to_grayscale() method to color maps

This PR adds a method to the ``Colormap`` base class which computes and returns a grayscale version of the map. This helps to quickly preview how various colormaps will appear when printed in grayscale.

This uses a formula derived empirically from photoshop's grayscale conversion; see http://alienryderflex.com/hsp.html for details.

As an example of the usage, we can quickly demonstrate one reason why everybody loves to rag on jet:

``` python
plt.figure(figsize=(8, 3))
im = np.random.rand(10, 10)

plt.subplot(121)
plt.imshow(im, cmap=plt.cm.jet)
plt.colorbar()

plt.subplot(122)
plt.imshow(im, cmap=plt.cm.jet.to_grayscale())
plt.colorbar()
```
![jet_example](https://cloud.githubusercontent.com/assets/781659/4436563/ab60dc6a-477a-11e4-828f-02a9dcd0c4cd.png)

I'm open to any suggestions or comments! I'm not sure if there are any complications with corner cases that I might be overlooking...