Skip to content

Conversation

staceybeck
Copy link

@staceybeck staceybeck commented Nov 17, 2019

The chart was not plotting the correct country name with the data point in the hover. Just needed to pass in the 'continent' column data from the continent_data dictionary.

Doc upgrade checklist:

  • random seed is set if using random data
  • file has been moved from unconverted/x/y.md to x/y.md
  • old boilerplate at top and bottom of file has been removed
  • Every example is independently runnable and is optimized for short line count
  • no more plot() or iplot()
  • graph_objs has been renamed to graph_objects
  • fig = <something> call is high up in each example
  • minimal creation of intermediate trace objects
  • liberal use of add_trace and update_layout
  • fig.show() at the end of each example
  • px example at the top if appropriate
  • minimize usage of hex codes for colors in favour of those in https://github.com/plotly/plotly.py-docs/issues/14

The chart was not plotting the correct country name with the data point in the hover.  Just needed to pass in the 'continent' column data from the continent_data dictionary.
@emmanuelle
Copy link
Contributor

Thank you @yecatstevir ! In fact I just noticed there are several issues with this example: in the hovertemplate x and y are inverted, and the population is the square root of the right value. I believe this part of the code should be

for continent_name, continent in continent_data.items():
    fig.add_trace(go.Scatter(
        x=continent['gdpPercap'],
        y=continent['lifeExp'],
        name=continent_name,
        text=continent['country'],
        customdata=continent['pop'],
        hovertemplate=
        "<b>%{text}</b><br><br>" +
        "GDP per Capita: %{x:$,.0f}<br>" +
        "Life Expectation: %{y:.0f}<br>" +
        "Population: %{customdata:,}" +
        "<extra></extra>",
        marker_size=continent['size'],
        ))

Does this sound correct to you? Thanks for noticing the problem :-)

@staceybeck
Copy link
Author

staceybeck commented Nov 18, 2019 via email

@emmanuelle
Copy link
Contributor

Happy to know you're having fun with Plotly ;-). Would you like to give it a try and make the other changes to this example?

@staceybeck
Copy link
Author

Ah yes, sorry about that, I will go back to take a look.

@nicolaskruchten
Copy link
Contributor

@emmanuelle if you have a chance, could you please move this over to the plotly.py repo, with the other fixes you found?

@gvwilson gvwilson closed this Jul 31, 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

Successfully merging this pull request may close these issues.

4 participants