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
- Updated Plotly.js to from version 2.6.3 to version 2.8.1. See the [plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#280----2021-12-10) for more information. Notable changes include:
You can add the `z` values as text to 2D Histogram points using `fig.update_traces(texttemplate="%{z}")`
85
+
### Displaying Text
86
+
87
+
*New in v5.5*
88
+
89
+
You can add the `z` values as text using the `text_auto` argument. Setting it to `True` will display the values on the bars, and setting it to a `d3-format` formatting string will control the output format.
Copy file name to clipboardExpand all lines: doc/python/annotated-heatmap.md
+81-71
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ jupyter:
8
8
format_version: '1.3'
9
9
jupytext_version: 1.13.4
10
10
kernelspec:
11
-
display_name: Python 3 (ipykernel)
11
+
display_name: Python 3
12
12
language: python
13
13
name: python3
14
14
language_info:
@@ -20,7 +20,7 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.7.11
23
+
version: 3.8.11
24
24
plotly:
25
25
description: How to make Annotated Heatmaps in Python with Plotly.
26
26
display_as: scientific
@@ -34,9 +34,11 @@ jupyter:
34
34
thumbnail: thumbnail/ann_heat.jpg
35
35
---
36
36
37
-
### Annotated Heatmaps with plotly.express and px.imshow
37
+
### Annotated Heatmaps with Plotly Express
38
38
39
-
These examples use [px.imshow](/python/imshow) to create Annotated Heatmaps. px.imshow is the recommended way to create heatmaps with z-annotations.
39
+
*New in v5.5*
40
+
41
+
As of version 5.5.0 of `plotly`, the **recommended way to [display annotated heatmaps is to use `px.imshow()`](/python/heatmaps/)** rather than the now-deprecated `create_annotated_heatmap` figure factory documented below for historical reasons.
40
42
41
43
42
44
#### Basic Annotated Heatmap for z-annotations
@@ -46,33 +48,19 @@ After creating a figure with `px.imshow`, you can add z-annotations with `.updat
46
48
```python
47
49
import plotly.express as px
48
50
49
-
df = px.data.medals_wide(indexed=True)
50
-
51
-
fig = px.imshow(df)
52
-
fig.update_traces(texttemplate="%{z}")
53
-
54
-
fig.show()
55
-
```
56
-
57
-
#### Custom Font
58
-
59
-
You can make changes to the font using `textfont`. Here we set the font size to 20.
60
-
61
-
```python
62
-
import plotly.express as px
63
-
64
-
df = px.data.medals_wide(indexed=True)
65
-
66
-
fig = px.imshow(df)
67
-
fig.update_traces(texttemplate="%{z}")
68
-
fig.update_traces(textfont={"size":20})
51
+
z = [[.1, .3, .5, .7, .9],
52
+
[1, .8, .6, .4, .2],
53
+
[.2, 0, .5, .7, .9],
54
+
[.9, .8, .4, .2, 0],
55
+
[.3, .4, .5, .7, 1]]
69
56
57
+
fig = px.imshow(z, text_auto=True)
70
58
fig.show()
71
59
```
72
60
73
-
### Annotated Heatmaps with [figure factory](/python/figure-factories/). For more examples with Heatmaps, see [this page](/python/heatmaps/).
61
+
### Deprecated Figure Factory
74
62
75
-
The remaining examples show how to create Annotated Heatmaps with [figure factory](/python/figure-factories/). For more examples with Heatmaps, see [this page](/python/heatmaps/).
63
+
The remaining examples show how to create Annotated Heatmaps with the deprecated `create_annotated_heatmap`[figure factory](/python/figure-factories/).
set `annotation_text` to a matrix with the same dimensions as `z`
83
+
84
+
> WARNING: this legacy figure factory requires the `y` array to be provided in reverse order, and will map the `z_text` to the `z` values in reverse order. **The use of the `px.imshow()` version below is highly recommended**
Here is a fairly contrived example showing how one can display a periodic table with custom text and hover using `ff.create_annotated_heatmap()` (scroll below to see the `px.imshow()` equivalent).
For more info on Plotly heatmaps, see: https://plotly.com/python/reference/heatmap/.<br> For more info on using colorscales with Plotly see: https://plotly.com/python/heatmap-and-contour-colorscales/ <br>For more info on `ff.create_annotated_heatmap()`, see the [full function reference](https://plotly.com/python-api-reference/generated/plotly.figure_factory.create_annotated_heatmap.html#plotly.figure_factory.create_annotated_heatmap)
0 commit comments