Skip to content

BUG: Fix a bug in plotting when using color array. #20726 #20727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 31, 2018
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ Plotting
- Bug in formatting tick labels with ``datetime.time()`` and fractional seconds (:issue:`18478`).
- :meth:`Series.plot.kde` has exposed the args ``ind`` and ``bw_method`` in the docstring (:issue:`18461`). The argument ``ind`` may now also be an integer (number of sample points).
- :func:`DataFrame.plot` now supports multiple columns to the ``y`` argument (:issue:`19699`)
- Bug in providing color array as color for a single plot (:issue:`20726`)


Groupby/Resample/Rolling
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _maybe_valid_colors(colors):
# mpl will raise error any of them is invalid
pass

if len(colors) != num_colors:
if len(colors) < num_colors:
try:
multiple = num_colors // len(colors) - 1
except ZeroDivisionError:
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/plotting/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,14 @@ def test_get_standard_colors_random_seed(self):
color1 = _get_standard_colors(1, color_type='random')
color2 = _get_standard_colors(1, color_type='random')
assert color1 == color2

def test_get_standard_colors_no_appending(self):
# GH20726

# Make sure not to add more colors so that matplotlib can cycle
# correctly.
from pandas.plotting._style import _get_standard_colors
from matplotlib import cm
color_before = cm.gnuplot(range(5))
color_after = _get_standard_colors(1, color=color_before)
assert len(color_after) == len(color_before)