Make NaNs transparent with pcolor
90 次查看(过去 30 天)
显示 更早的评论
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 个评论
J. Alex Lee
2020-2-27
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"
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!