yhat/ggplot — pull request #128 by gibbonorbiter (2013-12-13 21:12:55+00:00)
Title: force array containing figure axes to be 2d

First I want to say, I'm really grateful for the code so far! I came across an error when trying to plot all of my subplots in one row, instead of a 2D layout.

```
from pandas import DataFrame
from numpy.random import randn
from ggplot import *
letters = ['a','a','a','b','b','b','c','c','c','d','d','d']
colors = ['r','g','b','r','g','b','r','g','b','r','g','b']
values1 = randn(12)
values2 = randn(12)
df = pd.DataFrame({'letter': letters, 'color': colors, \
'value1': values1, 'value2': values2})

ggplot(aes(x='value1', y='value2', color='color'), df) \
+ geom_point() \
+ facet_wrap('letter', ncol=4)
```

raises the error:

```
//anaconda/lib/python2.7/site-packages/ggplot/ggplot.pyc in draw(self)
326 if self.legend:
327 if self.facets:
--> 328 ax = axs[0][self.n_wide - 1]
329 box = ax.get_position()
330 ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])

TypeError: 'AxesSubplot' object does not support indexing
```

The same thing happens when I try nrow=4. It has to do with the fact that plt.subplots() can return either a 1D or 2D array, but ggplot expects all 2D arrays. My quick, one-line fix was to just force the axis array to be 2D. I don't know the code all that well, so I don't know if this is a good fix (doesn't seem to break anything in my non-exhaustive tests), but mostly I wanted to bring this to your attention. Thanks again for your work!