add transparency to a contourf
39 views (last 30 days)
I have an image (a DEM.tif) inserted in the above script where I plotted a map created with contourf. the code is:
I should make the map transparent and therefore the contourf and not the .tif which instead must remain under the map.
I tried to write
but it made me transparent the DEM below instead of the variable s.
Can anyone help me?
Star Strider on 27 Nov 2022
You have to use the handle to the contourf plot to set the transparency —
[X,Y,Z] = peaks(50);
contourf(X, Y, Z) % Retunr No Information
[c,h] = contourf(X, Y, Z); % Return Contour Matrix ('c') & Handle ('h')
h.FaceAlpha = 0.5; % Set Transparency ('FaceAlpha') Value
You can use the same approach to set other properties to values different than the default values.
More Answers (1)
DGM on 27 Nov 2022
Edited: DGM on 27 Nov 2022
The FaceAlpha and EdgeAlpha properties are new in R2022b.
I'm not familiar with cotourfm() or mapping tools, so I can't comment on that. If you just have an image and an overlaid contourf() that you want to be semitransparent, you can still do that.
One possible way is to simply set the alpha of the descendant objects that make up the contour plot. That's verbose, but it works back to R2014b. This also allows you to set the transparency of the contour levels individually if desired.
The other way is to flip the stacking order and make the image transparent instead. If the image and plot cover each other completely, this is pretty simple to do. If the contourf() plot doesn't cover the entire image area, you'll have to create a second copy of the image to use as a background behind the contourf(). If your image is single-channel, you'll have to expand it.
See the following answers:
Editing primitives and doing inverted stacking:
Comment on using grayscale images with colormapped graphics objects: