-
Notifications
You must be signed in to change notification settings - Fork 1
texttemplate.py tutorial #151
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
Conversation
@emmanuelle if you can take a look at this while I'm away that would be super helpful 🙏 |
ok ! |
python/texttemplate.md
Outdated
v4upgrade: true | ||
--- | ||
|
||
### Add Text Template to Pie Chart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please switch to a more generic title: "Customizing displayed text with a Text Template"? The fact that it's a pie chart is not important here, you're introducing text templates, could be another chart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of comments (mostly I'm missing a few big-picture sentences about how to format these templates) but I hope it should be quick to address. Thanks!
yeah right, we usually include links to the reference page to not duplicate what we already have in those pages.. but I did include some information to make it more interesting! |
python/texttemplate.md
Outdated
### Customize Displayed Text with a Text Template | ||
To show an arbitrary text in your chart you can use [texttemplate](https://plot.ly/python/reference/#pie-texttemplate), which is a template string used for rendering the information, and will override [textinfo](https://plot.ly/python/reference/#treemap-textinfo). | ||
This template string can include `variables` in %{variable} format, `numbers` in [d3-format's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_forma), and `date` in [d3-time-fomrat's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format). | ||
`texttemplate` customizes the text that appears on your plot vs. [hovertemplate](https://plot.ly/python/reference/#pie-hovertemplate) customize the tooltip text. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hovertemplate customizeS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the changes! One more idea that I add: could you add one example with a plotly express figure and then call fig.update_traces
to show that it's possible to update figures created with px
?
We don't have texttemplate
in px
yet so fig.update_traces
can't update it.
I'm not sure I understand why you removed the example with |
This probably belongs in https://plot.ly/python/text-and-annotations/ rather than as a new file. |
python/text-and-annotations.md
Outdated
y = ["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"], | ||
x = [100, 60, 40, 20], | ||
textposition = "inside", | ||
texttemplate = "%{label}")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would actually be interesting to use a different date format here to show how to customize the format. But I can't get it to work... Maybe I'll ping you on this @nicolaskruchten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this could work for example
texttemplate = "%{y|%Y %b %-d}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's quite important to show an example with custom date formatting, because the formatting is quite specific
```python | ||
import plotly.graph_objects as go | ||
|
||
fig = go.Figure(go.Pie( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolaskruchten I think this is the pie chart example you were asking for, just using programming languages instead of revenue. Would you prefer having a more business-oriented example with dollars? (with the $ symbol in the template). @Mahdis-z you can give it a try with revenue by activity sector for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I chatted with Nicolas and he pointed out we would need an example of something which we cannot do with textinfo
, such as in the pie chart displaying the values as, for example, formatting 12 000 000 as $ 12M. @Mahdis-z could you please add such an example after the current pie chart example?
python/text-and-annotations.md
Outdated
|
||
fig = go.Figure(go.Pie( | ||
values = [40000000, 20000000, 30000000, 10000000], | ||
labels = ["Sales", "Profit", "Income", "Expenses"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this new example, the formatting looks really great! My only concern is that (if I'm not mistaken) usually you do not put sales profit income and expenses together on a bar chart because they are correlated (like profit is income minus expenses etc.). How about a pie chart about expenses : wages, operating expenses, cost of sales, advertising and promotion etc. (see for example https://canadianrestaurateur.wordpress.com/2012/05/28/how-to-compare-your-restaurant/#jp-carousel-184)
I left a tiny comment about labels in the pie chart but I don't need to review again, we're in 💃 land! |
Doc upgrade checklist:
unconverted/x/y.md
tox/y.md
plot()
oriplot()
graph_objs
has been renamed tograph_objects
fig = <something>
call is high up in each exampletrace
objectsadd_trace
andupdate_layout
fig.show()
at the end of each examplepx
example at the top if appropriate