Skip to content

hovertemplate.py #154

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

Merged
merged 8 commits into from
Nov 2, 2019
Merged

hovertemplate.py #154

merged 8 commits into from
Nov 2, 2019

Conversation

Mahdis-z
Copy link
Contributor

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

v4upgrade: true
---

### Add Hover Template to Pie Chart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the title to something more general about hovertemplate like "Customize tooltip text with a hovertemplate"?

### Add Hover Template to Pie Chart

To customize the tooltip on your graph you can use [hovertemplate](https://plot.ly/python/reference/#pie-hovertemplate), which is a template string used for rendering the information that appear on hoverbox.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a see also link to the tutorial on texttemplate you just wrote!

### Add Hover Template to Pie Chart

To customize the tooltip on your graph you can use [hovertemplate](https://plot.ly/python/reference/#pie-hovertemplate), which is a template string used for rendering the information that appear on hoverbox.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain here how to write the template string: which labels can be used, which formatting etc

import plotly.io as pio
import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use px.data.gapminder so that there's no need to download a file here?

A = {'target': df['continent'][[i]].unique()}
B.append(A)

data = [{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you define a Figure and a 'Scattertrace usinggoconstructors? Also usefig.showinstead ofpio.show`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's our preference, but we can't use graph_objects if we wanna use transform! Using transform helps to show information nicely in hovertemplate... let me see what would be the work around

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the explanation, now I understand better. We might need to ask @nicolaskruchten for advice here: do we want to insist of transform with this strange thing that we can't use go, or should we rather have people use px here (and hence do not have many examples with transform)?

Copy link
Contributor

@emmanuelle emmanuelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR, I've left a couple of comments, in the same spirit as the texttemplate PR.

@nicolaskruchten
Copy link
Contributor

So this documentation should be added to https://plot.ly/python/hover-text-and-formatting/ rather than made into a new file. And we should never use transforms in new documentation.

@Mahdis-z
Copy link
Contributor Author

So this documentation should be added to https://plot.ly/python/hover-text-and-formatting/ rather than made into a new file. And we should never use transforms in new documentation.

So its already added to https://plot.ly/python/hover-text-and-formatting/ and the new file was deleted, right?

@Mahdis-z Mahdis-z changed the title hovertext.py hovertemplate.py Nov 1, 2019
@emmanuelle
Copy link
Contributor

Could you also please:

@Mahdis-z
Copy link
Contributor Author

Mahdis-z commented Nov 1, 2019

Could you also please:

Thanks for the review, I made couple of changes. We keep v3 :)

```

### Advanced Hover Template
The following example shows how to format hover template. [Here](https://plot.ly/python/v3/hover-text-and-formatting/#dash-example) is an example to see how to format hovetemplate in Dash.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo hovetemplate


```python
import plotly.graph_objs as go
import plotly.io as pio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please port to v4 : graph_objects instead of graph_objs, and remove pio (we do not need a template here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops yes of course 👍

@emmanuelle
Copy link
Contributor

Thanks @Mahdis-z can you also add the dash example from the v3 page?

@Mahdis-z
Copy link
Contributor Author

Mahdis-z commented Nov 1, 2019

Thanks @Mahdis-z can you also add the dash example from the v3 page?

So I chatted with Nic and

Thanks @Mahdis-z can you also add the dash example from the v3 page?

Talked to Nicolas and he thinks we don't need to move Dash examples to this page!

@emmanuelle
Copy link
Contributor

ok!

@emmanuelle
Copy link
Contributor

thanks, 💃!

@Mahdis-z Mahdis-z merged commit e078df4 into master Nov 2, 2019
@Mahdis-z Mahdis-z deleted the hovertext_py branch November 2, 2019 05:49
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.

3 participants