Skip to content
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

BUG: Fix regression for RGB(A) color arguments #16701

Merged
merged 5 commits into from
Jun 16, 2017
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ I/O

Plotting
^^^^^^^^

- Fix regression in series plotting that prevented RGB and RGBA tuples from being used as color arguments (:issue:`16233`)



Expand Down
5 changes: 5 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ def _validate_color_args(self):
# support series.plot(color='green')
self.kwds['color'] = [self.kwds['color']]

if ('color' in self.kwds and isinstance(self.kwds['color'], tuple) and
self.nseries == 1 and len(self.kwds['color']) in (3, 4)):
# support RGB and RGBA tuples in series plot
self.kwds['color'] = [self.kwds['color']]

if ('color' in self.kwds or 'colors' in self.kwds) and \
self.colormap is not None:
warnings.warn("'color' and 'colormap' cannot be used "
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def test_color_single_series_list(self):
df = DataFrame({"A": [1, 2, 3]})
_check_plot_works(df.plot, color=['red'])

def test_rgb_tuple_color(self):
# GH 16695
df = DataFrame({'x': [1, 2], 'y': [3, 4]})
_check_plot_works(df.plot, x='x', y='y', color=(1, 0, 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the same but with the 4-len tuple as well?

_check_plot_works(df.plot, x='x', y='y', color=(1, 0, 0, 0.5))

def test_color_empty_string(self):
df = DataFrame(randn(10, 2))
with pytest.raises(ValueError):
Expand Down