How to make contourf image semitransparent?

I am using contourf to plot a 2D image in jet like below. Now I plan to make it semitransparent, therefore I may add some more lines. I tried all solutions searched online. Seems not working. Would anyone help me out?

 Respuesta aceptada

Bhanu Prakash
Bhanu Prakash el 11 de Jul. de 2024
Editada: Adam Danz el 12 de Jul. de 2024
Hi,
Starting in R2022b, to control the transparency of a 'contourf' plot, you can use the 'FaceAlpha' property in MATLAB. Here is an sample code for the same:
Z = peaks;
[M,c] = contourf(Z);
The range of 'FaceAlpha' is [0,1] with the deafult value being '1':
>> c.FaceAlpha
ans =
1
If you want to reduce the transparency, you can decrease the value of 'FaceAlpha' as follows:
c.FaceAlpha=0.3
Hope this helps!

3 comentarios

DGM
DGM el 12 de Jul. de 2024
Editada: DGM el 12 de Jul. de 2024
IIRC, this functionality requires R2022b or newer. While it's probably the appropriate answer today, older versions require different approaches.
Adam Danz
Adam Danz el 12 de Jul. de 2024
Thanks @Bhanu Prakash & @DGM, I added the release info to the answer.
DGM
DGM el 12 de Jul. de 2024
Thanks Adam. Idk what happened there, but this is a good outcome.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2019b

Etiquetas

Preguntada:

JZ
el 2 de Ag. de 2022

Comentada:

DGM
el 12 de Jul. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by