pydata/pandas — pull request #3860 by qwhelan (2013-06-12 06:57:17+00:00)
Title: Add colormap= argument to DataFrame plotting methods

I frequently plot DataFrames with a large number of columns and generally have difficulty distinguishing series due to the short cycle length of the default color scheme.

Especially in cases where the ordering of columns has significant information, the ideal way to color the series would be with a matplotlib colormap that uniformly spaces colors. This is pretty straightforward with pyplot, but pretty annoying to have to repeatedly do.

This patch modifies DataFrame plotting functions to take a ```colormap=``` argument consisting of either a ```str``` name of a [matplotlib colormap](http://wiki.scipy.org/Cookbook/Matplotlib/Show_colormaps) or a colormap object itself.

df.cumsum().plot(colormap='jet', figsize=(10,5))

![jet_10](https://f.cloud.github.com/assets/440095/641179/ed27a674-d327-11e2-86a3-85c64f80e294.png)

KDE plot:

df.plot(kind='kde', colormap='jet', figsize=(10,5))
![kde](https://f.cloud.github.com/assets/440095/641208/1f9ec6d6-d329-11e2-9c47-5cbf88c5fe30.png)

Some colormaps don't work as well on a white background (the 0 column is white):
df.cumsum().plot(colormap=cm.Greens, figsize=(10,5))
![greens_10](https://f.cloud.github.com/assets/440095/641183/18e0b134-d328-11e2-8436-94b26240a074.png)

But work better for other graph types:
df.plot(kind='bar', colormap='jet', figsize=(10,5))
![greens_bar](https://f.cloud.github.com/assets/440095/641185/56d57b28-d328-11e2-9412-ab6b40559ebc.png)

Parallel coordinates on the iris dataset:

parallel_coordinates(iris, 'Name', colormap='gist_rainbow')
![iris_parallel](https://f.cloud.github.com/assets/440095/641195/a207e32e-d328-11e2-910f-36576d187ff0.png)

Andrews curves (I'd appreciate someone double checking this one; don't think I have it quite right):

andrews_curves(iris, 'Name', colormap='winter')
![andrews_winter](https://f.cloud.github.com/assets/440095/641201/e1acf85c-d328-11e2-8a8c-263d9abc12f9.png)

I've included some test coverage and unified all the color creation code into one method ```_get_standard_colors()```. I started adding to the documentation but ran into a weird issue with the sphinx plot output. When adding this to ```visualization.rst```:

.. ipython:: python

from matplotlib import cm

df = DataFrame(randn(1000, 4), index=ts.index, columns=list('ABCD'))
df = df.cumsum()

plt.figure()

@savefig greens.png width=6in
df.plot(colormap=cm.Greens)

I get this output (the lines should be white->green):
![greens](https://f.cloud.github.com/assets/440095/641261/d7243762-d32b-11e2-9bb0-e135ae25546b.png)

My first thought was that it was the ```options.display.mpl_style = 'default'```, but plots render fine in IPython with this setting. My guess is something in ```@savefig```, but is anyone familiar with what might be happening here?