Skip to content

Commit 03ee0c1

Browse files
author
Tom Augspurger
committed
Merge pull request #11865 from rcarneva/master
look for colormap in rcParams['axes.prop_cycle'] (mpl 1.5+) first
2 parents 6b8a721 + bbfcbd1 commit 03ee0c1

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

doc/source/whatsnew/v0.18.0.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ Bug Fixes
326326

327327
- Bug in parsing timezone offset strings with non-zero minutes (:issue:`11708`)
328328

329-
330-
329+
- Bug in ``df.plot`` using incorrect colors for bar plots under matplotlib 1.5+ (:issue:`11614`)
331330

332331
- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
333332
- Bug in ``pd.rolling_median`` where memory allocation failed even with sufficient memory (:issue:`11696`)

pandas/tests/test_graphics.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -3716,6 +3716,24 @@ def test_plain_axes(self):
37163716
Series(rand(10)).plot(ax=ax)
37173717
Series(rand(10)).plot(ax=iax)
37183718

3719+
def test_passed_bar_colors(self):
3720+
import matplotlib as mpl
3721+
color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
3722+
colormap = mpl.colors.ListedColormap(color_tuples)
3723+
barplot = pd.DataFrame([[1,2,3]]).plot(kind="bar", cmap=colormap)
3724+
self.assertEqual(color_tuples, [c.get_facecolor() for c in barplot.patches])
3725+
3726+
def test_rcParams_bar_colors(self):
3727+
import matplotlib as mpl
3728+
color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
3729+
try: # mpl 1.5
3730+
with mpl.rc_context(rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
3731+
barplot = pd.DataFrame([[1,2,3]]).plot(kind="bar")
3732+
except (AttributeError, KeyError): # mpl 1.4
3733+
with mpl.rc_context(rc={'axes.color_cycle': color_tuples}):
3734+
barplot = pd.DataFrame([[1,2,3]]).plot(kind="bar")
3735+
self.assertEqual(color_tuples, [c.get_facecolor() for c in barplot.patches])
3736+
37193737

37203738
@tm.mplskip
37213739
class TestDataFrameGroupByPlots(TestPlotBase):
@@ -3763,7 +3781,6 @@ def test_plot_submethod_works(self):
37633781
df.groupby('z')['x'].plot.line()
37643782
tm.close()
37653783

3766-
37673784
def assert_is_valid_plot_return_object(objs):
37683785
import matplotlib.pyplot as plt
37693786
if isinstance(objs, np.ndarray):

pandas/tools/plotting.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
163163
if color_type == 'default':
164164
# need to call list() on the result to copy so we don't
165165
# modify the global rcParams below
166-
colors = list(plt.rcParams.get('axes.color_cycle',
167-
list('bgrcmyk')))
166+
try:
167+
colors = [c['color'] for c in list(plt.rcParams['axes.prop_cycle'])]
168+
except KeyError:
169+
colors = list(plt.rcParams.get('axes.color_cycle',
170+
list('bgrcmyk')))
168171
if isinstance(colors, compat.string_types):
169172
colors = list(colors)
170173
elif color_type == 'random':

0 commit comments

Comments
 (0)