I know set_bad can colour the pixel into a specific colour but in my example I only want to have edge colour for blue and grey pixels with values and not the bad pixels (red) import matplotlib.pyplot as plt import xarray as xr import numpy as np from matplotlib import colors fig, ax = plt.subplots(1, 1, figsize=(12, 8)) # provide example data array with a mixture of floats and nans in them data = xr.DataArray([np.random.rand(10, 10)]) # Example data # set a few nans data[0, 1, 1] = np.nan data[0, 1, 2] = np.nan data[0, 1, 3] = np.nan data[0, 2, 1] = np.nan data[0, 2, 2] = np.nan data[0, 2, 3] = np.nan data[0, 3, 1] = np.nan data[0, 3, 2] = np.nan data[0, 3, 3] = np.nan cmap = colors.ListedColormap(['#2c7bb6', "#999999"]) # make nan trends invalid and set edgecolour to white cmap.set_bad(color = 'red') data.plot(edgecolor = "grey", cmap = cmap) Continue reading...