Rgb#

import hvplot.xarray  # noqa

rgb can be used to display images that are distributed as three separate “channels” or “bands”.

from hvplot.sample_data import landuse

da = landuse(landuse='airplane', id=90).read()
da
/usr/share/miniconda/envs/hvplotdocs/lib/python3.11/site-packages/xarray/core/dataarray.py:1426: FutureWarning: None value for 'chunks' is deprecated. It will raise an error in the future. Use instead '{}'
  warnings.warn(
/usr/share/miniconda/envs/hvplotdocs/lib/python3.11/site-packages/intake_xarray/image.py:474: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  'dims': dict(ds2.dims),
<xarray.DataArray (y: 256, x: 256, channel: 3)> Size: 197kB
array([[[123, 113, 106],
        [120, 110, 103],
        [119, 107, 103],
        ...,
        [172, 160, 148],
        [174, 162, 150],
        [174, 163, 152]],

       [[124, 114, 107],
        [124, 112, 106],
        [120, 107, 104],
        ...,
        [171, 159, 147],
        [172, 161, 149],
        [173, 162, 151]],

       [[118, 109, 104],
        [114, 104,  98],
        [114, 103,  98],
        ...,
...
        ...,
        [ 91,  77,  62],
        [ 92,  75,  64],
        [ 91,  75,  66]],

       [[164, 156, 148],
        [172, 165, 155],
        [174, 167, 156],
        ...,
        [ 89,  74,  61],
        [ 90,  72,  61],
        [ 89,  71,  61]],

       [[164, 157, 148],
        [158, 151, 141],
        [156, 150, 139],
        ...,
        [ 88,  74,  60],
        [ 88,  69,  58],
        [ 89,  70,  58]]], dtype=uint8)
Coordinates:
  * y        (y) int64 2kB 0 1 2 3 4 5 6 7 8 ... 248 249 250 251 252 253 254 255
  * x        (x) int64 2kB 0 1 2 3 4 5 6 7 8 ... 248 249 250 251 252 253 254 255
  * channel  (channel) int64 24B 0 1 2

Since rgb images are stored starting at the top left pixel, we should start there when plotting to make sure that we get the picture in the correct orientation. To accomplish this, we use flip_yaxis.

da.hvplot.rgb(x='x', y='y', bands='channel', data_aspect=1, flip_yaxis=True, xaxis=False, yaxis=None)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.