Skip to content
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ Plotting

- Bug in :func:`DataFrame.plot.scatter` and :func:`DataFrame.plot.hexbin` caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611`, :issue:`10678`, and :issue:`20455`)
- Bug in plotting a Series with datetimes using :func:`matplotlib.axes.Axes.scatter` (:issue:`22039`)
- Bug in :func:`DataFrame.plot.bar` caused bars to use multiple colors instead of a single one (:issue:`20585`)
- Bug in validating color parameter caused extra color to be appended to the given color array. This happened to multiple plotting functions using matplotlib. (:issue:`20726`)

Groupby/Resample/Rolling
Expand Down
4 changes: 3 additions & 1 deletion pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,9 @@ def boxplot(data, column=None, by=None, ax=None, fontsize=None,
column = 'x'

def _get_colors():
return _get_standard_colors(color=kwds.get('color'), num_colors=1)
# num_colors=3 is required as method maybe_color_bp takes the colors
# in positions 0 and 2.
return _get_standard_colors(color=kwds.get('color'), num_colors=3)

def maybe_color_bp(bp):
if 'color' not in kwds:
Expand Down
2 changes: 2 additions & 0 deletions pandas/plotting/_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
list('bgrcmyk')))
if isinstance(colors, compat.string_types):
colors = list(colors)

colors = colors[0:num_colors]
elif color_type == 'random':
import pandas.core.common as com

Expand Down
31 changes: 29 additions & 2 deletions pandas/tests/plotting/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def test_parallel_coordinates_with_sorted_labels(self):

df = DataFrame({"feat": [i for i in range(30)],
"class": [2 for _ in range(10)] +
[3 for _ in range(10)] +
[1 for _ in range(10)]})
[3 for _ in range(10)] +
[1 for _ in range(10)]})
ax = parallel_coordinates(df, 'class', sort_labels=True)
polylines, labels = ax.get_legend_handles_labels()
color_label_tuples = \
Expand Down Expand Up @@ -310,6 +310,33 @@ def test_get_standard_colors_random_seed(self):
color2 = _get_standard_colors(1, color_type='random')
assert color1 == color2

def test_get_standard_colors_default_num_colors(self):
from pandas.plotting._style import _get_standard_colors

# Make sure the default color_types returns the specified amount
color1 = _get_standard_colors(1, color_type='default')
color2 = _get_standard_colors(9, color_type='default')
color3 = _get_standard_colors(20, color_type='default')
assert len(color1) == 1
assert len(color2) == 9
assert len(color3) == 20

def test_plot_single_color(self):
# Example from #20585. All 3 bars should have the same color
df = DataFrame({'account-start': ['2017-02-03', '2017-03-03',
'2017-01-01'],
'client': ['Alice Anders', 'Bob Baker',
'Charlie Chaplin'],
'balance': [-1432.32, 10.43, 30000.00],
'db-id': [1234, 2424, 251],
'proxy-id': [525, 1525, 2542],
'rank': [52, 525, 32],
})
ax = df.client.value_counts().plot.bar()
colors = lmap(lambda rect: rect.get_facecolor(),
ax.get_children()[0:3])
assert all(color == colors[0] for color in colors)

def test_get_standard_colors_no_appending(self):
# GH20726

Expand Down