Skip to content

Commit 583fa5a

Browse files
authored
Series.plot doesn't allow color=None (pandas-dev#51967)
1 parent 2a983bb commit 583fa5a

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Period
198198

199199
Plotting
200200
^^^^^^^^
201-
-
201+
- Bug in :meth:`Series.plot` when invoked with ``color=None`` (:issue:`51953`)
202202
-
203203

204204
Groupby/resample/rolling

pandas/plotting/_matplotlib/core.py

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def _validate_color_args(self):
377377
if (
378378
"color" in self.kwds
379379
and self.nseries == 1
380+
and self.kwds["color"] is not None
380381
and not is_list_like(self.kwds["color"])
381382
):
382383
# support series.plot(color='green')

pandas/tests/plotting/frame/test_frame_color.py

+7
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,10 @@ def test_invalid_colormap(self):
659659
msg = "(is not a valid value)|(is not a known colormap)"
660660
with pytest.raises((ValueError, KeyError), match=msg):
661661
df.plot(colormap="invalid_colormap")
662+
663+
def test_dataframe_none_color(self):
664+
# GH51953
665+
df = DataFrame([[1, 2, 3]])
666+
ax = df.plot(color=None)
667+
expected = self._unpack_cycler(self.plt.rcParams)[:3]
668+
self._check_colors(ax.get_lines(), linecolors=expected)

pandas/tests/plotting/test_series.py

+7
Original file line numberDiff line numberDiff line change
@@ -848,3 +848,10 @@ def test_timedelta_index(self, index):
848848
xlims = (3, 1)
849849
ax = Series([1, 2], index=index).plot(xlim=(xlims))
850850
assert ax.get_xlim() == (3, 1)
851+
852+
def test_series_none_color(self):
853+
# GH51953
854+
series = Series([1, 2, 3])
855+
ax = series.plot(color=None)
856+
expected = self._unpack_cycler(self.plt.rcParams)[:1]
857+
self._check_colors(ax.get_lines(), linecolors=expected)

0 commit comments

Comments
 (0)