Skip to content

Commit

Permalink
BUG: correctly handle color keyword for Series/DataFrame bar plots, #958
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Apr 10, 2012
1 parent cb730a7 commit 1ac953b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def test_plot(self):
_check_plot_works(self.series[:5].plot, kind='line')
_check_plot_works(self.series[:5].plot, kind='barh')
_check_plot_works(self.series[:10].plot, kind='barh')

Series(np.random.randn(10)).plot(kind='bar',color='black')

@slow
def test_hist(self):
_check_plot_works(self.ts.hist)
Expand Down
16 changes: 9 additions & 7 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,25 +394,27 @@ def _make_plot(self):
K = self.nseries

for i, (label, y) in enumerate(self._iter_data()):

kwds = self.kwds.copy()
if 'color' not in kwds:
kwds['color'] = colors[i % len(colors)]

if self.subplots:
ax = self.axes[i]
rect = bar_f(ax, self.ax_pos, y, 0.5, start=pos_prior,
linewidth=1, **self.kwds)
linewidth=1, **kwds)
ax.set_title(label)
elif self.stacked:
mask = y > 0
start = np.where(mask, pos_prior, neg_prior)

rect = bar_f(ax, self.ax_pos, y, 0.5, start=start,
color=colors[i % len(colors)],
label=label, linewidth=1,
**self.kwds)
label=label, linewidth=1, **kwds)
pos_prior = pos_prior + np.where(mask, y, 0)
neg_prior = neg_prior + np.where(mask, 0, y)
else:
rect = bar_f(ax, self.ax_pos + i * 0.75 / K, y, 0.75 / K,
start=pos_prior, label=label,
color=colors[i % len(colors)],
**self.kwds)
start=pos_prior, label=label, **kwds)
rects.append(rect)
labels.append(label)

Expand Down

0 comments on commit 1ac953b

Please sign in to comment.