Skip to content

Pandas custom color plotting not working for multiple values #17516

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
jolespin opened this issue Sep 13, 2017 · 3 comments
Closed

Pandas custom color plotting not working for multiple values #17516

jolespin opened this issue Sep 13, 2017 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request

Comments

@jolespin
Copy link

I am trying to do a barplot where the positive values are a certain color and the negative values are another color. I have scripts that I've used in previous versions where this was working but the current version isn't working. I am basing it off of a code snippet from: https://stackoverflow.com/questions/22311139/matplotlib-bar-chart-choose-color-if-value-is-positive-vs-value-is-negative

Is there something in the backend of the plotting wrapper that is stoping multiple color values from working?

# Versions
print("Python Version:", sys.version)
print()
print("Pandas Version:", pd.__version__)

# Input Data
data = {'M00001': 0.099999999999999978, 'M00003': 0.125, 'M00004': -0.14200000000000007, 'M00005': -1.0, 'M00007': -0.25, 'M00017': 0.14300000000000002, 'M00021': -1.0, 'M00023': -0.25, 'M00034': 0.097000000000000003, 'M00035': -0.25, 'M00048': -0.122, 'M00050': -0.25, 'M00053': -0.125, 'M00060': 0.11099999999999999, 'M00063': -0.25, 'M00115': 0.59999999999999998, 'M00116': -0.11099999999999999, 'M00126': -0.14300000000000002, 'M00127': -0.39999999999999997, 'M00144': -0.15400000000000003, 'M00149': 0.25, 'M00157': -0.125, 'M00173': -0.090000000000000024, 'M00178': -0.17300000000000004, 'M00179': -0.10399999999999998, 'M00188': 0.33300000000000002, 'M00240': -0.33299999999999996, 'M00242': -0.33299999999999996, 'M00256': 0.5, 'M00335': -0.125, 'M00359': -0.050000000000000044, 'M00360': -0.05600000000000005, 'M00377': 0.14299999999999996, 'M00459': 0.5, 'M00481': 0.5, 'M00504': 0.5, 'M00527': 0.1429999999999999, 'M00530': -0.5, 'M00532': 0.10000000000000001, 'M00549': 0.66700000000000004, 'M00609': 0.16699999999999998, 'M00614': -0.083000000000000018, 'M00618': 0.11200000000000004, 'M00628': -0.25, 'M00695': -0.33300000000000002, 'M00723': -0.25, 'M00728': 0.33300000000000002, 'M00754': 0.33300000000000002, 'M00793': -0.25, 'M90000': -0.11400000000000005, 'M91000': -0.070000000000000007}
Se_data =  pd.Series(data)

# Pandas Plotting
with plt.style.context("seaborn-white"):
    fig, ax = plt.subplots(figsize=(5,10))
    Se_data.plot(kind="barh", ax=ax, color=Se_data.map(lambda x: {True:"blue", False:"red"}[x > 0]))

image

@TomAugspurger
Copy link
Contributor

I think this is a duplicate of #16822, which is going to be fixed by #17360 (I just need to rebase and merge it). So this will be fixed in the next release, ~2 weeks away.

@TomAugspurger TomAugspurger added the Duplicate Report Duplicate issue or pull request label Sep 13, 2017
@jolespin
Copy link
Author

Perfect, just making sure I'm not the only one.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 13, 2017 via email

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
Projects
None yet
Development

No branches or pull requests

2 participants