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: CHANGELOG.md
+6-1
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7
7
### Fixed
8
8
- Fixed ValueError when `ff.create_annotated_heatmap` passes `rgba()` colors into `to_rgb_color_list`[#3478](https://github.com/plotly/plotly.py/issues/3478)
9
9
10
+
### Added
11
+
12
+
-`text_auto` argument to `px.bar`, `px.histogram`, `px.density_heatmap`, `px.imshow`[#3518](https://github.com/plotly/plotly.py/issues/3518)
- Updated Plotly.js to from version 2.6.3 to version 2.8.0. 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:
16
+
- 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
+100-46
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).
0 commit comments