Skip to content

Commit 1968b09

Browse files
committed
imshow examples, plus minor edits
1 parent ec44961 commit 1968b09

File tree

5 files changed

+63
-26
lines changed

5 files changed

+63
-26
lines changed

doc/python/annotated-heatmap.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
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
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.7
23+
version: 3.7.11
2424
plotly:
2525
description: How to make Annotated Heatmaps in Python with Plotly.
2626
display_as: scientific
@@ -34,9 +34,52 @@ jupyter:
3434
thumbnail: thumbnail/ann_heat.jpg
3535
---
3636

37-
#### Simple Annotated Heatmap
37+
### Annotated Heatmaps with plotly.express and px.imshow
38+
39+
40+
These examples use [px.imshow](/python/imshow) to create Annotated Heatmaps. px.imshow is the best way creating heatmaps with z-annotations.
41+
42+
43+
#### Basic Annotated Heatmap for z-annotations
44+
45+
46+
After creating a figure with `px.imshow`, you can add z-annotations with `.update_traces(texttemplate="%{z}")`.
47+
48+
```python
49+
import plotly.express as px
50+
51+
df = px.data.medals_wide(indexed=True)
52+
53+
fig = px.imshow(df)
54+
fig.update_traces(texttemplate="%{z}")
55+
56+
fig.show()
57+
```
58+
59+
#### Custom Font
60+
61+
62+
You can make changes to the font using `textfont`. Here we set the font size to 20.
3863

39-
This page details the use of a [figure factory](/python/figure-factories/). For more examples with Heatmaps, see [this page](/python/heatmaps/).
64+
```python
65+
import plotly.express as px
66+
67+
df = px.data.medals_wide(indexed=True)
68+
69+
fig = px.imshow(df)
70+
fig.update_traces(texttemplate="%{z}")
71+
fig.update_traces(textfont={"size":20})
72+
73+
fig.show()
74+
```
75+
76+
### Annotated Heatmaps with [figure factory](/python/figure-factories/). For more examples with Heatmaps, see [this page](/python/heatmaps/).
77+
78+
79+
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/).
80+
81+
82+
#### Simple Annotated Heatmap
4083

4184
```python
4285
import plotly.figure_factory as ff
@@ -201,6 +244,12 @@ fig.update_layout(title_text='Periodic Table')
201244
fig.show()
202245
```
203246

247+
#### Annotations with plotly.express
248+
249+
```python
250+
251+
```
252+
204253
#### Reference
205254

206255
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)

doc/python/colorscales.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ fig.show()
521521
### Color Bar Displayed Horizontally
522522

523523

524-
By default, color bars are displayed vertically. You can change a color bar to be displayed horizontally by setting `orientation`=`h`.
524+
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`.
525525

526526
```python
527527
import plotly.graph_objects as go
@@ -539,17 +539,7 @@ fig = go.Figure()
539539

540540
fig.add_trace(go.Heatmap(
541541
z=dataset["z"],
542-
colorbar=dict(
543-
title="Surface Heat",
544-
titleside="top",
545-
tickmode="array",
546-
tickvals=[2, 50, 100],
547-
ticktext=["Cool", "Mild", "Hot"],
548-
ticks="outside",
549-
orientation='h'
550-
551-
)
552-
))
542+
colorbar=dict(orientation='h')))
553543

554544
fig.show()
555545
```

doc/python/heatmaps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fig.show()
216216
### Text on Heatmap Points
217217

218218

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`.
219+
In this example we add text to heatmap points using `texttemplate`. We use the values of the `text` attribute for the text. We also adjust the font size using `textfont`.
220220

221221
```python
222222
import plotly.graph_objects as go

doc/python/histograms.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,7 @@ fig.show()
362362
### Histogram Bar Text
363363

364364

365-
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`.
366-
367-
365+
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`.
368366

369367
```python
370368
import plotly.graph_objects as go

doc/python/imshow.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
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
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.11
2424
plotly:
2525
description: How to display image data in Python with Plotly.
2626
display_as: scientific

0 commit comments

Comments
 (0)