Skip to content

Commit e64b05a

Browse files
committed
label
1 parent 11414e0 commit e64b05a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

doc/python/imshow.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ fig.show()
112112

113113
### Display an xarray image with px.imshow
114114

115-
[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 below.
115+
[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 in the next example.
116116

117117
```python
118118
import plotly.express as px
119119
import xarray as xr
120120
# Load xarray from dataset included in the xarray tutorial
121121
airtemps = xr.tutorial.open_dataset('air_temperature').air.sel(lon=250.0)
122122
fig = px.imshow(airtemps.T, color_continuous_scale='RdBu_r', origin='lower',
123-
labels={'colorbar':airtemps.attrs['var_desc']})
123+
#labels={'colorbar':airtemps.attrs['var_desc']}
124+
)
124125
fig.show()
125126
```
126127

packages/python/plotly/plotly/express/_imshow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def imshow(
182182
img_is_xarray = True
183183
if aspect is None:
184184
aspect = "auto"
185-
z_name = img.attrs["long_name"] if "long_name" in img.attrs else ""
185+
z_name = xarray.plot.utils.label_from_attrs(img).replace("\n", "<br>")
186186
colorbar_title = z_name
187187

188188
if labels is not None:

0 commit comments

Comments
 (0)