You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/heatmaps.md
+19-2Lines changed: 19 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,22 @@ fig.update_xaxes(side="top")
86
86
fig.show()
87
87
```
88
88
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
+
89
105
### Basic Heatmap with `plotly.graph_objects`
90
106
91
107
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()
200
216
### Text on Heatmap Points
201
217
202
218
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`.
0 commit comments