Skip to content
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

Pandas backend color scatter not working #3956

Closed
astrowonk opened this issue Nov 16, 2022 · 7 comments
Closed

Pandas backend color scatter not working #3956

astrowonk opened this issue Nov 16, 2022 · 7 comments

Comments

@astrowonk
Copy link

Plotly 5.11
Pandas 1.5.1

Easy reproduction here:

import plotly.express as px
df = px.data.iris()
px.scatter(df, x="sepal_width", y="sepal_length", color="species")
df.plot.scatter(x="sepal_width", y="sepal_length", color="species")

Screenshot 2022-11-16 at 7 44 47 AM

@nicolaskruchten
Copy link
Contributor

Hmm there's something strange going on here because it works for me, and the output above seems inconsistent with what I would expect to see. Normally you should only see a single figure output (the last one) unless you call .show() on each of them.

Here's what I see:

image

@astrowonk
Copy link
Author

astrowonk commented Nov 16, 2022

@nicolaskruchten That is simply because I have it set up to show all output, so I get both figures (or both of anything, when multiple lines have variables in them)

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

On the question of the plot and the the color; what version of plotly/pandas are you using? I've definitely not had this problem until now!

@nicolaskruchten
Copy link
Contributor

OK. It works for Pandas 1.2 but not 1.5. Someone'll have to dig into what the new version of Pandas is doing differently... The relevant code in our repo is here, for reference: https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/plotly/__init__.py#L99

@astrowonk
Copy link
Author

astrowonk commented Nov 16, 2022

Pandas turned color into an alias for 'c' which then removes color from the kwarg list becaues they pop it out, and then plotly doesn't have the argument.

I opened pandas-dev/pandas#49732. Please comment there or upvote, etc! I don't think there's any easy workaround for plotly's code other than to use a different keyword like colour, etc.

@nicolaskruchten
Copy link
Contributor

Nice work, thanks very much 🙏

@AaronStiff
Copy link
Contributor

@nicolaskruchten That pandas change was successfully reverted in pandas-dev/pandas#49836, but the code example @astrowonk gave is still returning an error:

ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not ['species']

I think it's because pandas can't map an array of categories to colours (mentioned here: pandas-dev/pandas#16485 (comment)). Is that correct?

@gvwilson
Copy link
Contributor

gvwilson commented Jul 5, 2024

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Alternatively, if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

@gvwilson gvwilson closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants