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: doc/python/heatmaps.md
+18-4
Original file line number
Diff line number
Diff line change
@@ -36,9 +36,7 @@ jupyter:
36
36
37
37
### Heatmap with `plotly.express` and `px.imshow`
38
38
39
-
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly. With `px.imshow`, each value of the input array is represented as a heatmap pixel.
40
-
41
-
`px.imshow` makes opiniated choices for representing heatmaps, such as using square pixels. To override this behaviour, you can use `fig.update_layout` or use the `go.Heatmap` trace from `plotly.graph_objects` as described below.
39
+
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on "tidy" data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/). With `px.imshow`, each value of the input array is represented as a heatmap pixel.
42
40
43
41
For more examples using `px.imshow`, see the [tutorial on displaying image data with plotly](/python/imshow).
44
42
@@ -51,6 +49,22 @@ fig = px.imshow([[1, 20, 30],
51
49
fig.show()
52
50
```
53
51
52
+
### Customizing the axes and labels on a heatmap
53
+
54
+
You can use the `x`, `y` and `labels` arguments to customize the display of a heatmap, and use `.update_xaxes()` to move the x axis tick labels to the top:
If Plotly Express does not provide a good starting point, it is also possible to use the more generic `go.Heatmap` function from `plotly.graph_objects`.
@@ -67,7 +81,7 @@ fig.show()
67
81
68
82
### Heatmap with Categorical Axis Labels
69
83
70
-
In this example we also show how to ignore [hovertext](https://plot.ly/python/hover-text-and-formatting/) when we have [missing values](https://plot.ly/python/missing_values) in the data by setting the [hoverongaps](https://plot.ly/python/reference/#heatmap-hoverongaps) to False.
84
+
In this example we also show how to ignore [hovertext](https://plot.ly/python/hover-text-and-formatting/) when we have [missing values](https://plot.ly/python/missing_values) in the data by setting the [hoverongaps](https://plot.ly/python/reference/#heatmap-hoverongaps) to False.
Copy file name to clipboardExpand all lines: doc/python/imshow.md
+61-6
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ jupyter:
6
6
extension: .md
7
7
format_name: markdown
8
8
format_version: '1.2'
9
-
jupytext_version: 1.3.0
9
+
jupytext_version: 1.3.1
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.7.3
23
+
version: 3.6.8
24
24
plotly:
25
25
description: How to display image data in Python with Plotly.
26
26
display_as: scientific
@@ -74,7 +74,7 @@ fig = px.imshow(img)
74
74
fig.show()
75
75
```
76
76
77
-
### Display single-channel 2D image as grayscale
77
+
### Display single-channel 2D data as a heatmap
78
78
79
79
For a 2D image, `px.imshow` uses a colorscale to map scalar data to colors. The default colorscale is the one of the active template (see [the tutorial on templates](/python/templates/)).
80
80
@@ -88,6 +88,17 @@ fig.show()
88
88
89
89
### Choose the colorscale to display a single-channel image
90
90
91
+
You can customize the [continuous color scale](/python/colorscales/) just like with any other Plotly Express function:
### Customizing the axes and labels on a single-channel image
127
+
128
+
You can use the `x`, `y` and `labels` arguments to customize the display of a heatmap, and use `.update_xaxes()` to move the x axis tick labels to the top:
[xarrays](http://xarray.pydata.org/en/stable/) are labeled arrays (with labeled axes and coordinates). If you pass an xarray image to `px.imshow`, its axes labels and coordinates will be used for axis titles. If you don't want this behavior, you can pass `img.values` which is a NumPy array if `img` is an xarray. Alternatively, you can override axis titles hover labels and colorbar title using the `labels` attribute, as above.
145
+
146
+
```python
147
+
import plotly.express as px
148
+
import xarray as xr
149
+
# Load xarray from dataset included in the xarray tutorial
For xarrays, by default `px.imshow` does not constrain pixels to be square, since axes often correspond to different physical quantities (e.g. time and space), contrary to a plain camera image where pixels are square (most of the time). If you want to impose square pixels, set the parameter `aspect` to "equal" as below.
0 commit comments