EOA-team / eodal

Earth Observation Data Analysis Library
https://eodal.readthedocs.io/en/latest/
GNU General Public License v3.0
93 stars 15 forks source link

Enhancment: use same background for masked pixels between plot_band and plot_multiple_bands #56

Closed atoparseks closed 1 year ago

atoparseks commented 1 year ago

When I use scene.plot_multiple_bands, masked pixels are black: image

For one band I can use scene.plot_band , and the masked pixels are white

I suggest white for both cases. Or black. This doesn't look good when placed side to side. image

lukasValentin commented 1 year ago

Hi @atoparseks, I fully agree - I actually wanted to address this issue already a while ago and remember that I gave up a bit frustrated because matplotlib ignored the color argument for the background. But we should definitely solve the issue and also five the user the chance to use a custom background color.

lukasValentin commented 1 year ago

Hi @atoparseks, I now figured out how to change the color of the nodata pixels, i.e., those pixels masked out. To do so, I added a new optional keyword argument in RasterCollection.plot_multiple_bands named nodata_color. By default it is set to 'white' to mimic the default behavior of the Band.plot method.

nodata_color can be set, however, to any color name available in matplotlib (see here for a full list of named colors).

The code snippet below shows the usage:

from eodal.core.band import Band, GeoInfo
from eodal.core.raster import RasterCollection

import numpy as np

# open sample data
rc = RasterCollection.from_multi_band_raster(fpath_raster='data/20190530_T32TMT_MSIL2A_S2A_pixel_division_10m.tiff')
# mask some pixels so we can test the new functionality
masked = rc.mask(mask=rc['B8A'] > 1000, bands_to_mask=rc.band_names)

# no-data colored white [255,255,255] (new default) -> same no-data color as Band.plot
masked.plot_multiple_bands(band_selection=['B02', 'B03', 'B04'], nodata_color='white')

# i.e., omitting the nodata_color argument will have the same effect as the
# previous statement
masked.plot_multiple_bands(band_selection=['B02', 'B03', 'B04'])

# no-data colored black [0,0,0] (old default until version 0.2.0)
masked.plot_multiple_bands(band_selection=['B02', 'B03', 'B04'], nodata_color='black')

# no-data colored in an example matplotlib color, e.g. "red"
masked.plot_multiple_bands(band_selection=['B02', 'B03', 'B04'], nodata_color='red')

# or some other color, e.g., "darkkhaki"
masked.plot_multiple_bands(band_selection=['B02', 'B03', 'B04'], nodata_color='darkkhaki')
lukasValentin commented 1 year ago

I close this issue since it is resolved by #61

atoparseks commented 1 year ago

Thanks! Looks really neat!