Skip to content

Plotly Express strange hover_data ValueError #1683

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
suciokhan opened this issue Jul 24, 2019 · 7 comments · Fixed by #4083
Closed

Plotly Express strange hover_data ValueError #1683

suciokhan opened this issue Jul 24, 2019 · 7 comments · Fixed by #4083

Comments

@suciokhan
Copy link

Scatter plotting with no problems, until I attempted to map a column of my data to hover_data.
Here's what my data looks like. I'm trying to map the most_similar_kt column to hover_data.

image

Here's the error message:
ValueError: Element of value of 'hover_data' is not the name of a column in 'data_frame'. Expected one of ['x', 'y', 'label', 'freq', 'similarity', 'size', 'class', 'most_similar_kt'] but received: m

And here's my code:
fig = px.scatter(df, x='x',y='y', color='similarity', size='size', symbol='class',hover_name='label', hover_data='most_similar_kt', width=1500, height=1000, template='plotly_dark', render_mode='webgl')

Apologies if this has already been addressed; I spent 10 minutes googling for errors and it doesn't appear anyone else had this issue.

If I remove the hover_data assignment, then the plot works:
image

Thanks for your assistance!

@suciokhan suciokhan changed the title Strange hover_data ValueError Plotly Express strange hover_data ValueError Jul 24, 2019
@suciokhan
Copy link
Author

Apologies; I figure out that you are supposed to feed columns inside a list rather than just a string of the column name like the other items. Closing out.

@zhaomh1998
Copy link

Had the exact same issue. This is indeed a very misleading error message though, and very much seem to be a bug as it says Expected one of ['x', 'y', 'label', 'freq', 'similarity', 'size', 'class', 'most_similar_kt'] but received: m, as you passed in hover_data='most_similar_kt'.

It would make sense if it says something like "list of column names expected but received a single str".

@emmanuelle
Copy link
Contributor

@zhaomh1998 we have an open issue #2177 to improve the error message, it should be improved soon :-).

@boral
Copy link

boral commented Feb 4, 2021

Please fix this.

@nicolaskruchten
Copy link
Contributor

We haven't gotten around to it yet... Contributions are welcome :)

@rocu-mapspeople
Copy link

just came here to say these comments helped me. :)

@StankovskiA
Copy link

The answers have helped me as well. For other newbies like myself, to pass all the columns you can do
hover_data = df.columns.tolist()
and to pass just certain columns
hover_data = [ 'col1', 'col2']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants