You can set the AlphaData
of the image object to ~isnan(data)
so that NaN displays as transparent values.
R = rand(10); R(R < 0.25) = NaN; him = imshow(R, 'InitialMagnification', 10000); colormap parula set(him, 'AlphaData', ~isnan(R))

If you need a specific color, you can turn on the axes and set the color of the axes like any color that should have NaN
values.
axis on; % Make a red axis set(gca, 'XColor', 'none', 'yColor', 'none', 'xtick', [], 'ytick', [], 'Color', 'r')

If you use pcolor
, then NaN
values ββare already considered transparent.
Suver
source share