Skip to content

Commit 51f5aef

Browse files
author
“mahdis-z”
committed
revisions
1 parent fe30afb commit 51f5aef

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

python/texttemplate.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jupyter:
4040
### Customize Displayed Text with a Text Template
4141
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).
4242
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).
43-
`texttemplate` customizes the text that appears on your plot vs. [hovertemplate](https://plot.ly/python/reference/#pie-hovertemplate) customize the tooltip text.
43+
`texttemplate` customizes the text that appears on your plot vs. [hovertemplate](https://plot.ly/python/reference/#pie-hovertemplate) that customizes the tooltip text.
4444

4545
```python
4646
import plotly.graph_objects as go
@@ -76,6 +76,7 @@ fig.show()
7676
```
7777
### Set Date in Text Template
7878
The following example shows how to show date by setting [axis.type](https://plot.ly/python/reference/#layout-yaxis-type) in [funnel charts](https://plot.ly/python/funnel-charts/).
79+
As you can see [textinfo](https://plot.ly/python/reference/#funnel-textinfo) and [texttemplate](https://plot.ly/python/reference/#funnel-texttemplate) have the same functionality when you want to determine 'just' the trace information on the graph.
7980

8081
```python
8182
from plotly import graph_objects as go
@@ -102,3 +103,20 @@ fig.update_layout(yaxis = {'type': 'date'})
102103

103104
fig.show()
104105
```
106+
107+
```python
108+
import plotly.express as px
109+
import plotly.graph_objects as go
110+
111+
gapminder = px.data.gapminder()
112+
fig = px.scatter(gapminder.query("year==2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent",
113+
hover_name="country", log_x=True, size_max=60)
114+
115+
fig.update_traces(go.Scatter(texttemplate = '%{y}'))
116+
117+
fig.show()
118+
```
119+
120+
```python
121+
122+
```

0 commit comments

Comments
 (0)