Skip to content

Bar and box plots always use the 'default' matplotlib colormap, even the style is changed #12029

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

Closed
halflings opened this issue Jan 13, 2016 · 5 comments
Labels
Duplicate Report Duplicate issue or pull request Visualization plotting
Milestone

Comments

@halflings
Copy link

I set the matplotlib style to "fivethirtyeight", which changes many settings in the axes, colors, etc.

This is what I get when doing a simple line plot:

pd.DataFrame(dict(a=[1, 2, 3], b=[5, 10, 2])).plot.line()

plot1

The style matches what I was expecting.

(hist, area and other type of plots I tried work as well)

But when I want to get a bar plot, I get this:

pd.DataFrame(dict(a=[1, 2, 3], b=[5, 10, 2])).plot.bar()

plot2

Most elements of the style seem to be here, but the colors are the default matplotlib ones, not the ones in "fivethirtyeight" (and the same goes with a boxplot)

plot3

Any clue about what might be causing this?

These are the lines I used to style my plots:

import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('fivethirtyeight')

%matplotlib inline

COLORS = [(0.3333333333333333, 0.6588235294117647, 0.40784313725490196),
 (0.2980392156862745, 0.4470588235294118, 0.6901960784313725),
 (0.7686274509803922, 0.3058823529411765, 0.3215686274509804),
 (0.5058823529411764, 0.4470588235294118, 0.6980392156862745),
 (0.8, 0.7254901960784313, 0.4549019607843137),
 (0.39215686274509803, 0.7098039215686275, 0.803921568627451),
 (0.33999999999999997, 0.86, 0.57920000000000016)]

plt.rcParams['figure.figsize'] = (14.0, 7.0)
plt.rcParams['axes.prop_cycle'] = plt.cycler('color', COLORS)
@halflings
Copy link
Author

For boxplots at least, the problem might come from this:

https://github.com/pydata/pandas/blob/03ee0c19c99583da915139fbaec855e66322f5f3/pandas/tools/plotting.py#L2668

(it's using a custom _get_colors that doesn't pass a colormap)

@jorisvandenbossche
Copy link
Member

The bar plot issue should be solved in master (see issue #11614 and PR https://github.com/pydata/pandas/pull/11865/files). Are you able to test that?

The boxplots issue also seems OK when I try it with master, but probably it would be good to add a test for that as well.

@jorisvandenbossche jorisvandenbossche added the Duplicate Report Duplicate issue or pull request label Jan 14, 2016
@jorisvandenbossche jorisvandenbossche added this to the 0.18.0 milestone Jan 14, 2016
@halflings
Copy link
Author

Great, thanks Joris!

@halflings
Copy link
Author

It turns out that this issue also arises when using matplotlib alone, without pandas. I filed an issue on the matplotlib repo referencing this one.

@halflings
Copy link
Author

Just tested, and the issue is solved on master. Closing this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Visualization plotting
Projects
None yet
Development

No branches or pull requests

2 participants