Repository: pandas-dev/pandas

Issue:
BUG: scatter plot with error bars broken on master
This example works on 0.14.1 but not master:

```
%matplotlib inline
import numpy as np
import pandas as pd
np.random.seed(12345)
df = pd.DataFrame(np.random.rand(10, 5), columns=['a', 'b', 'c', 'd', 'e'])
df.plot(x='a', y='b', xerr='c', yerr='d', kind='scatter')
```

I get:

```
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-1-38e437a109be> in <module>()
      4 np.random.seed(12345)
      5 df = pd.DataFrame(np.random.rand(10, 5), columns=['a', 'b', 'c', 'd', 'e'])
----> 6 df.plot(x='a', y='b', xerr='c', yerr='d', kind='scatter')

/Users/shoyer/dev/pandas/pandas/tools/plotting.pyc in plot_frame(frame, x, y, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, style, title, xlim, ylim, logx, logy, xticks, yticks, kind, sort_columns, fontsize, secondary_y, layout, **kwds)
   2223                              secondary_y=secondary_y, layout=layout, **kwds)
   2224 
-> 2225     plot_obj.generate()
   2226     plot_obj.draw()
   2227     return plot_obj.result

/Users/shoyer/dev/pandas/pandas/tools/plotting.pyc in generate(self)
    911         self._compute_plot_data()
    912         self._setup_subplots()
--> 913         self._make_plot()
    914         self._add_table()
    915         self._make_legend()

/Users/shoyer/dev/pandas/pandas/tools/plotting.pyc in _make_plot(self)
   1402 
   1403         errors_x = self._get_errorbars(label=x, index=0, yerr=False)
-> 1404         errors_y = self._get_errorbars(label=y, index=1, xerr=False)
   1405         if len(errors_x) > 0 or len(errors_y) > 0:
   1406             err_kwds = dict(errors_x, **errors_y)

/Users/shoyer/dev/pandas/pandas/tools/plotting.pyc in _get_errorbars(self, label, index, xerr, yerr)
   1362                         err = None
   1363                 elif index is not None and err is not None:
-> 1364                     err = err[index]
   1365 
   1366                 if err is not None:

IndexError: index 1 is out of bounds for axis 0 with size 1
```



Discussion:
Found this was caused by #7736. Will consider the better fix.
https://github.com/pydata/pandas/pull/7736/files#diff-21d1f541e135453f7da4eb2399ad5037R1388


Resolving patch:
diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py
--- a/pandas/tools/plotting.py
+++ b/pandas/tools/plotting.py
@@ -1394,15 +1394,13 @@ def _make_plot(self):
             label = None
         scatter = ax.scatter(data[x].values, data[y].values, label=label,
                              **self.kwds)
-
         self._add_legend_handle(scatter, label)
 
         errors_x = self._get_errorbars(label=x, index=0, yerr=False)
-        errors_y = self._get_errorbars(label=y, index=1, xerr=False)
+        errors_y = self._get_errorbars(label=y, index=0, xerr=False)
         if len(errors_x) > 0 or len(errors_y) > 0:
             err_kwds = dict(errors_x, **errors_y)
-            if 'color' in self.kwds:
-                err_kwds['color'] = self.kwds['color']
+            err_kwds['ecolor'] = scatter.get_facecolor()[0]
             ax.errorbar(data[x].values, data[y].values, linestyle='none', **err_kwds)
 
     def _post_plot_logic(self):


Test patch:
diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py
--- a/pandas/tests/test_graphics.py
+++ b/pandas/tests/test_graphics.py
@@ -349,7 +349,6 @@ def _check_has_errorbars(self, axes, xerr=0, yerr=0):
         yerr : number
             expected number of y errorbar
         """
-
         axes = self._flatten_visible(axes)
         for ax in axes:
             containers = ax.containers
@@ -2805,12 +2804,28 @@ def test_errorbar_scatter(self):
         self._check_has_errorbars(ax, xerr=0, yerr=0)
         ax = _check_plot_works(df.plot, kind='scatter', x='x', y='y', xerr=df_err)
         self._check_has_errorbars(ax, xerr=1, yerr=0)
+
         ax = _check_plot_works(df.plot, kind='scatter', x='x', y='y', yerr=df_err)
         self._check_has_errorbars(ax, xerr=0, yerr=1)
         ax = _check_plot_works(df.plot, kind='scatter', x='x', y='y',
                                xerr=df_err, yerr=df_err)
         self._check_has_errorbars(ax, xerr=1, yerr=1)
 
+        def _check_errorbar_color(containers, expected, has_err='has_xerr'):
+            errs = [c.lines[1][0] for c in ax.containers if getattr(c, has_err, False)]
+            self._check_colors(errs, linecolors=[expected] * len(errs))
+
+        # GH 8081
+        df = DataFrame(np.random.randn(10, 5), columns=['a', 'b', 'c', 'd', 'e'])
+        ax = df.plot(kind='scatter', x='a', y='b', xerr='d', yerr='e', c='red')
+        self._check_has_errorbars(ax, xerr=1, yerr=1)
+        _check_errorbar_color(ax.containers, 'red', has_err='has_xerr')
+        _check_errorbar_color(ax.containers, 'red', has_err='has_yerr')
+
+        ax = df.plot(kind='scatter', x='a', y='b', yerr='e', color='green')
+        self._check_has_errorbars(ax, xerr=0, yerr=1)
+        _check_errorbar_color(ax.containers, 'green', has_err='has_yerr')
+
 
 @tm.mplskip
 class TestDataFrameGroupByPlots(TestPlotBase):