Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ Bug Fixes

- Bug in ``pivot_table`` performed with nameless ``index`` and ``columns`` raises ``KeyError`` (:issue:`8103`)

- Bug in ``DataFrame.plot(kind='scatter')`` draws points and errorbars with different colors when the color is specified by ``c`` keyword (:issue:`8081`)



Expand Down
17 changes: 16 additions & 1 deletion pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down