Skip to content

look for colormap in rcParams['axes.prop_cycle'] (mpl 1.5+) first #11865

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

Merged
merged 1 commit into from
Dec 25, 2015
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
3 changes: 1 addition & 2 deletions doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ Bug Fixes

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



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

- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
- Bug in ``pd.rolling_median`` where memory allocation failed even with sufficient memory (:issue:`11696`)
Expand Down
19 changes: 18 additions & 1 deletion pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3716,6 +3716,24 @@ def test_plain_axes(self):
Series(rand(10)).plot(ax=ax)
Series(rand(10)).plot(ax=iax)

def test_passed_bar_colors(self):
import matplotlib as mpl
color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
colormap = mpl.colors.ListedColormap(color_tuples)
barplot = pd.DataFrame([[1,2,3]]).plot(kind="bar", cmap=colormap)
self.assertEqual(color_tuples, [c.get_facecolor() for c in barplot.patches])

def test_rcParams_bar_colors(self):
import matplotlib as mpl
color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
try: # mpl 1.5
with mpl.rc_context(rc={'axes.prop_cycle': mpl.cycler("color", color_tuples)}):
barplot = pd.DataFrame([[1,2,3]]).plot(kind="bar")
except (AttributeError, KeyError): # mpl 1.4
with mpl.rc_context(rc={'axes.color_cycle': color_tuples}):
barplot = pd.DataFrame([[1,2,3]]).plot(kind="bar")
self.assertEqual(color_tuples, [c.get_facecolor() for c in barplot.patches])


@tm.mplskip
class TestDataFrameGroupByPlots(TestPlotBase):
Expand Down Expand Up @@ -3763,7 +3781,6 @@ def test_plot_submethod_works(self):
df.groupby('z')['x'].plot.line()
tm.close()


def assert_is_valid_plot_return_object(objs):
import matplotlib.pyplot as plt
if isinstance(objs, np.ndarray):
Expand Down
7 changes: 5 additions & 2 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
if color_type == 'default':
# need to call list() on the result to copy so we don't
# modify the global rcParams below
colors = list(plt.rcParams.get('axes.color_cycle',
list('bgrcmyk')))
try:
colors = [c['color'] for c in list(plt.rcParams['axes.prop_cycle'])]
except KeyError:
colors = list(plt.rcParams.get('axes.color_cycle',
list('bgrcmyk')))
if isinstance(colors, compat.string_types):
colors = list(colors)
elif color_type == 'random':
Expand Down