Make NaNs transparent with pcolor
91 views (last 30 days)
Show older comments
Hello,
I have a matrix with NaNs and other values. I plot in the background a land mask on which the values overlay. But, because of this the NaNs also overlay the background and I end up not seeing it anymore. I would therefore like to make the NaNs transparent so we can see the background.
So far I was using imagesc but because of a georeference issue, pcolor is more adapted. I had the following code to maks NaNs transparent with imagesc:
f2 = figure('Visible',true);
% Plot the background image
ax1 = axes;
imagesc(ax1, demx, demy, maskLand);
hold on;
% Plot the overlay image
ax2 = axes;
% Make NaNs transparent
imAlpha = ones(size(overlay));
imAlpha(isnan(overlay)) = 0;
imagesc(ax2, demx, demy, overlay, 'AlphaData', imAlpha);
Now, with pcolor I have been setting:
pcolor(maskLand...)
hold on
e1 = pcolor(overlay)
set(e1,'facealpha',0.3)
But it sets the whole overlay as transparent while I only want the NaNs of the overlay to be transparent. What can I specify to make this happen ?
Have a nice day !
2 Comments
J. Alex Lee
on 27 Feb 2020
I'm not sure why your first strategy of setting the alphadata doesn't work, as long as you are placing the overlay in the same axes as the background (ax1 rather than ax2).
f2 = figure('Visible',true);
% Plot the background image
ax = axes("NextPlot","add");
imagesc(ax, demx, demy, maskLand);
% Plot the overlay image
% Make NaNs transparent
imAlpha = 0.3*ones(size(overlay)); % want to make it translucent?
imAlpha(isnan(overlay)) = 0;
imagesc(ax, demx, demy, overlay, 'AlphaData', imAlpha);
Or if you are trying to stack axes, you would need to make sure the axes themselves do not have a color by setting their "Color" to "none"
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!