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
Before opening an issue, please search for existing and closed issues. If your problem or idea is not addressed yet, [please open a new issue](https://github.com/plotly/plotly.py/issues/new).
3
+
Before opening an issue, please search for existing and closed issues :)
4
4
5
-
Bug reports **must**be accompanied with a reproducible example. Please use the [latest version](https://github.com/plotly/plotly.py/blob/master/CHANGELOG.md) of plotly.py in your report unless not applicable and specify if you're plotting [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting).
5
+
**Please**accompany bug reports with a reproducible example. Please use the [latest version](https://github.com/plotly/plotly.py/blob/master/CHANGELOG.md) of plotly.py in your report unless not applicable.
6
6
7
-
Note that GitHub issues are reserved for bug reports and feature requests only. Implementation questions should be asked on community.plot.ly (tagged [`python`](https://community.plot.ly/c/api/python)) or on Stack Overflow (tagged [`plotly`](https://stackoverflow.com/questions/tagged/plotly)).
8
-
9
-
Comments on GitHub issues or pull requests should add content to the discussions. Approbation comments such as *+1* or *I would like this feature to be implemented as well* will be deleted by the maintainers. Please use [GitHub reactions](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments) instead.
7
+
Note that GitHub Issues are meant to be used for bug reports and feature requests only. Implementation or usage questions should be asked on [community.plotly.com](https://community.plotly.com/c/graphing-libraries/python/10) or on Stack Overflow (tagged [`plotly`](https://stackoverflow.com/questions/tagged/plotly)).
- 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 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.
By passing in a `z` value and a `histfunc`, density heatmaps can perform basic aggregation operations. Here we show average Sepal Length grouped by Petal Length and Petal Width for the Iris dataset.
@@ -235,5 +249,24 @@ fig.update_layout(
235
249
fig.show()
236
250
```
237
251
252
+
### Text on 2D Histogram Points
253
+
254
+
In this example we add text to 2D Histogram points. We use the values from the `z` attribute for the text.
255
+
256
+
```python
257
+
import plotly.graph_objects as go
258
+
from plotly import data
259
+
260
+
df = data.tips()
261
+
262
+
fig = go.Figure(go.Histogram2d(
263
+
x=df.total_bill,
264
+
y=df.tip,
265
+
texttemplate="%{z}"
266
+
))
267
+
268
+
fig.show()
269
+
```
270
+
238
271
#### Reference
239
272
See https://plotly.com/python/reference/histogram2d/ for more information and chart attribute options!
Copy file name to clipboardExpand all lines: doc/python/annotated-heatmap.md
+92-43
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.1'
9
-
jupytext_version: 1.1.1
8
+
format_version: '1.3'
9
+
jupytext_version: 1.13.4
10
10
kernelspec:
11
11
display_name: Python 3
12
12
language: python
@@ -20,7 +20,7 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.6.7
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,56 +34,55 @@ jupyter:
34
34
thumbnail: thumbnail/ann_heat.jpg
35
35
---
36
36
37
-
#### Simple Annotated Heatmap
37
+
### Annotated Heatmaps with Plotly Express
38
+
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.
42
+
43
+
44
+
#### Basic Annotated Heatmap for z-annotations
38
45
39
-
This page details the use of a [figure factory](/python/figure-factories/). For more examples with Heatmaps, see [this page](/python/heatmaps/).
46
+
After creating a figure with `px.imshow`, you can add z-annotations with `.update_traces(texttemplate="%{z}")`.
40
47
41
48
```python
42
-
import plotly.figure_factoryasff
49
+
import plotly.expressaspx
43
50
44
51
z = [[.1, .3, .5, .7, .9],
45
52
[1, .8, .6, .4, .2],
46
53
[.2, 0, .5, .7, .9],
47
54
[.9, .8, .4, .2, 0],
48
55
[.3, .4, .5, .7, 1]]
49
56
50
-
fig =ff.create_annotated_heatmap(z)
57
+
fig =px.imshow(z, text_auto=True)
51
58
fig.show()
52
59
```
53
60
54
-
#### Defined Colorscale
61
+
###Deprecated Figure Factory
55
62
56
-
```python
57
-
import plotly.figure_factory as ff
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`
86
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