Skip to content

Commit 0230bbf

Browse files
author
Chang She
committed
BUG: allow full color name as string when plotting single column frame
1 parent 9cf39ac commit 0230bbf

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

pandas/tests/test_graphics.py

+9
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def test_bar_colors(self):
8787
rs = rect.get_facecolor()
8888
self.assert_(xp == rs)
8989

90+
plt.close('all')
91+
df.ix[:, [0]].plot(kind='bar', color='DodgerBlue')
92+
9093
@slow
9194
def test_bar_linewidth(self):
9295
df = DataFrame(np.random.randn(5, 5))
@@ -493,6 +496,12 @@ def test_line_colors(self):
493496
finally:
494497
sys.stderr = tmp
495498

499+
# make color a list if plotting one column frame
500+
# handles cases like df.plot(color='DodgerBlue')
501+
plt.close('all')
502+
df.ix[:, [0]].plot(color='DodgerBlue')
503+
504+
496505
class TestDataFrameGroupByPlots(unittest.TestCase):
497506

498507
@classmethod

pandas/tools/plotting.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,23 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=True,
553553

554554
self.kwds = kwds
555555

556+
self._validate_color_args()
557+
558+
def _validate_color_args(self):
559+
from pandas import DataFrame
560+
if 'color' not in self.kwds and 'colors' in self.kwds:
561+
warnings.warn(("'colors' is being deprecated. Please use 'color'"
562+
"instead of 'colors'"))
563+
colors = self.kwds.pop('colors')
564+
self.kwds['color'] = colors
565+
566+
if ('color' in self.kwds and
567+
(isinstance(self.data, Series) or
568+
isinstance(self.data, DataFrame) and len(self.data.columns) ==1 )):
569+
#support series.plot(color='green')
570+
self.kwds['color'] = [self.kwds['color']]
571+
572+
556573
def _iter_data(self):
557574
from pandas.core.frame import DataFrame
558575
if isinstance(self.data, (Series, np.ndarray)):
@@ -858,14 +875,6 @@ class LinePlot(MPLPlot):
858875
def __init__(self, data, **kwargs):
859876
self.mark_right = kwargs.pop('mark_right', True)
860877
MPLPlot.__init__(self, data, **kwargs)
861-
if 'color' not in self.kwds and 'colors' in self.kwds:
862-
warnings.warn(("'colors' is being deprecated. Please use 'color'"
863-
"instead of 'colors'"))
864-
colors = self.kwds.pop('colors')
865-
self.kwds['color'] = colors
866-
if 'color' in self.kwds and isinstance(self.data, Series):
867-
#support series.plot(color='green')
868-
self.kwds['color'] = [self.kwds['color']]
869878

870879
def _index_freq(self):
871880
from pandas.core.frame import DataFrame

0 commit comments

Comments
 (0)