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
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 +246,24 @@ fig.update_layout(
235
246
fig.show()
236
247
```
237
248
249
+
### Text on 2D Histogram Points
250
+
251
+
In this example we add text to 2D Histogram points. We use the values from the `z` attribute for the text.
252
+
253
+
```python
254
+
import plotly.graph_objects as go
255
+
from plotly import data
256
+
257
+
df = data.tips()
258
+
259
+
fig = go.Figure(go.Histogram2d(
260
+
x=df.total_bill,
261
+
y=df.tip,
262
+
texttemplate="%{z}"
263
+
))
264
+
265
+
fig.show()
266
+
```
267
+
238
268
#### Reference
239
269
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
+45-6
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ 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
-
display_name: Python 3
11
+
display_name: Python 3 (ipykernel)
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.6.7
23
+
version: 3.7.11
24
24
plotly:
25
25
description: How to make Annotated Heatmaps in Python with Plotly.
26
26
display_as: scientific
@@ -34,9 +34,48 @@ jupyter:
34
34
thumbnail: thumbnail/ann_heat.jpg
35
35
---
36
36
37
-
#### Simple Annotated Heatmap
37
+
### Annotated Heatmaps with plotly.express and px.imshow
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.
40
+
41
+
42
+
#### Basic Annotated Heatmap for z-annotations
43
+
44
+
After creating a figure with `px.imshow`, you can add z-annotations with `.update_traces(texttemplate="%{z}")`.
45
+
46
+
```python
47
+
import plotly.express as px
48
+
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
38
58
39
-
This page details the use of a [figure factory](/python/figure-factories/). For more examples with Heatmaps, see [this page](/python/heatmaps/).
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})
69
+
70
+
fig.show()
71
+
```
72
+
73
+
### Annotated Heatmaps with [figure factory](/python/figure-factories/). For more examples with Heatmaps, see [this page](/python/heatmaps/).
74
+
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/).
Copy file name to clipboardExpand all lines: doc/python/colorscales.md
+31-6
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.2'
9
-
jupytext_version: 1.6.0
8
+
format_version: '1.3'
9
+
jupytext_version: 1.13.4
10
10
kernelspec:
11
-
display_name: Python 3
11
+
display_name: Python 3 (ipykernel)
12
12
language: python
13
13
name: python3
14
14
language_info:
@@ -20,10 +20,10 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.7.6
23
+
version: 3.7.11
24
24
plotly:
25
-
description: How to set, create and control continuous color scales and color bars
26
-
in scatter, bar, map and heatmap figures.
25
+
description: How to set, create and control continuous color scales and color
26
+
bars in scatter, bar, map and heatmap figures.
27
27
display_as: file_settings
28
28
has_thumbnail: true
29
29
ipynb: ~notebook_demo/187
@@ -518,6 +518,31 @@ fig.add_trace(go.Heatmap(
518
518
fig.show()
519
519
```
520
520
521
+
### Color Bar Displayed Horizontally
522
+
523
+
By default, color bars are displayed vertically. You can change a color bar to be displayed horizontally by setting the `colorbar``orientation` attribute to `h`.
To share colorscale information in multiple subplots, you can use [coloraxis](https://plotly.com/javascript/reference/scatter/#scatter-marker-line-coloraxis).
Copy file name to clipboardExpand all lines: doc/python/heatmaps.md
+39-4
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.2'
9
-
jupytext_version: 1.6.0
8
+
format_version: '1.3'
9
+
jupytext_version: 1.13.4
10
10
kernelspec:
11
-
display_name: Python 3
11
+
display_name: Python 3 (ipykernel)
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.6
23
+
version: 3.7.11
24
24
plotly:
25
25
description: How to make Heatmaps in Python with Plotly.
26
26
display_as: scientific
@@ -86,6 +86,21 @@ fig.update_xaxes(side="top")
86
86
fig.show()
87
87
```
88
88
89
+
### Adding and customizing text on points
90
+
91
+
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`.
92
+
93
+
```python
94
+
import plotly.express as px
95
+
96
+
df = px.data.medals_wide(indexed=True)
97
+
fig = px.imshow(df)
98
+
fig.update_traces(texttemplate="%{z}")
99
+
fig.update_traces(textfont={"size":20})
100
+
101
+
fig.show()
102
+
```
103
+
89
104
### Basic Heatmap with `plotly.graph_objects`
90
105
91
106
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/).
@@ -197,6 +212,26 @@ fig.update_layout(
197
212
fig.show()
198
213
```
199
214
215
+
### Text on Heatmap Points
216
+
217
+
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`.
218
+
219
+
```python
220
+
import plotly.graph_objects as go
221
+
222
+
fig = go.Figure(data=go.Heatmap(
223
+
z=[[1, 20, 30],
224
+
[20, 1, 60],
225
+
[30, 60, 1]],
226
+
text=[['one', 'twenty', 'thirty'],
227
+
['twenty', 'one', 'sixty'],
228
+
['thirty', 'sixty', 'one']],
229
+
texttemplate="%{text}",
230
+
textfont={"size":20}))
231
+
232
+
fig.show()
233
+
```
234
+
200
235
### Heatmap and datashader
201
236
202
237
Arrays of rasterized values build by datashader can be visualized using
Copy file name to clipboardExpand all lines: doc/python/histograms.md
+31-4
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.2'
9
-
jupytext_version: 1.4.2
8
+
format_version: '1.3'
9
+
jupytext_version: 1.13.4
10
10
kernelspec:
11
-
display_name: Python 3
11
+
display_name: Python 3 (ipykernel)
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.7
23
+
version: 3.7.11
24
24
plotly:
25
25
description: How to make Histograms in Python with Plotly.
26
26
display_as: statistical
@@ -208,6 +208,18 @@ fig = px.histogram(df, x="total_bill", color="sex", marginal="rug", # can be `bo
208
208
fig.show()
209
209
```
210
210
211
+
### Adding bar text
212
+
213
+
You can add text to histogram bars using `fig.update_traces(texttemplate="%{variable}")`, where `variable` is the text to add. In this example, we add the y-axis values to the bars.
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Histogram` class from `plotly.graph_objects`](/python/graph-objects/). All of the available histogram options are described in the histogram section of the reference page: https://plotly.com/python/reference#histogram.
@@ -340,6 +352,21 @@ fig.update_layout(
340
352
fig.show()
341
353
```
342
354
355
+
### Histogram Bar Text
356
+
357
+
You can add text to histogram bars using the `texttemplate` argument. In this example we add the x-axis values as text following the format `%{variable}`. We also adjust the size of the text using `textfont_size`.
0 commit comments