Skip to content

Commit 5b0083b

Browse files
kjfordTomAugspurger
authored andcommitted
BUG: Fix regression for RGB(A) color arguments (#16701)
* Add test * Pass tuples that are RGB or RGBA like in list * Update what's new * change whatsnew to reflect regression fix * Add test for RGBA as well (cherry picked from commit 125c414)
1 parent 7e6f0b9 commit 5b0083b

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.20.3.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ I/O
5959

6060
Plotting
6161
^^^^^^^^
62-
62+
- Fix regression in series plotting that prevented RGB and RGBA tuples from being used as color arguments (:issue:`16233`)
6363

6464

6565

pandas/plotting/_core.py

+5
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ def _validate_color_args(self):
186186
# support series.plot(color='green')
187187
self.kwds['color'] = [self.kwds['color']]
188188

189+
if ('color' in self.kwds and isinstance(self.kwds['color'], tuple) and
190+
self.nseries == 1 and len(self.kwds['color']) in (3, 4)):
191+
# support RGB and RGBA tuples in series plot
192+
self.kwds['color'] = [self.kwds['color']]
193+
189194
if ('color' in self.kwds or 'colors' in self.kwds) and \
190195
self.colormap is not None:
191196
warnings.warn("'color' and 'colormap' cannot be used "

pandas/tests/plotting/test_frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ def test_color_single_series_list(self):
158158
df = DataFrame({"A": [1, 2, 3]})
159159
_check_plot_works(df.plot, color=['red'])
160160

161+
def test_rgb_tuple_color(self):
162+
# GH 16695
163+
df = DataFrame({'x': [1, 2], 'y': [3, 4]})
164+
_check_plot_works(df.plot, x='x', y='y', color=(1, 0, 0))
165+
_check_plot_works(df.plot, x='x', y='y', color=(1, 0, 0, 0.5))
166+
161167
def test_color_empty_string(self):
162168
df = DataFrame(randn(10, 2))
163169
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)