Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48795aa

Browse files
committed
Added px example, edited graph objects example
1 parent 87c9a10 commit 48795aa

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

doc/python/heatmaps.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ fig.update_xaxes(side="top")
8686
fig.show()
8787
```
8888

89+
### Adding and customizing text on points
90+
91+
92+
You can add text to heatmap points with `.update_traces(texttemplate="%{variable}")`. Here we use the values of the `z` attribute for `variable`. We also customize the font size with `textfont`.
93+
94+
```python
95+
import plotly.express as px
96+
97+
df = px.data.medals_wide(indexed=True)
98+
fig = px.imshow(df)
99+
fig.update_traces(texttemplate="%{z}")
100+
fig.update_traces(textfont={"size":20})
101+
102+
fig.show()
103+
```
104+
89105
### Basic Heatmap with `plotly.graph_objects`
90106

91107
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Heatmap` class from `plotly.graph_objects`](/python/graph-objects/).
@@ -200,7 +216,7 @@ fig.show()
200216
### Text on Heatmap Points
201217

202218

203-
In this example we add text to heatmap points. We use the values from the `text` attribute for the text.
219+
In this example we add text to heatmap points using `texttemplate`. We use the values from the `text` attribute for the text. We also adjust the font size using `textfont`.
204220

205221
```python
206222
import plotly.graph_objects as go
@@ -212,7 +228,8 @@ fig = go.Figure(data=go.Heatmap(
212228
text=[['one', 'twenty', 'thirty'],
213229
['twenty', 'one', 'sixty'],
214230
['thirty', 'sixty', 'one']],
215-
texttemplate="%{text}"))
231+
texttemplate="%{text}",
232+
textfont={"size":20}))
216233

217234
fig.show()
218235
```

0 commit comments

Comments
 (0)