How to make one contour transparent in contourf?

Hello, I have a contour plot with several layers define as follows:
[c,h]=contourf(X,Y,Z,[value1 value2 value3 value4]);
I would like to make a selected contour transparent, let's say the first contour defined by value1. Any thought on how to proceed? Thanks.
Arnault

 Respuesta aceptada

José-Luis
José-Luis el 28 de En. de 2013
[C,h] = contourf(peaks(20),-4:1:4);
allH = allchild(h);
valueToHide = 1;
patchValues = cell2mat(get(allH,'UserData'));
patchesToHide = patchValues == valueToHide;
set(allH(patchesToHide),'FaceColor','k','FaceAlpha',0.8);
Note that you could set the FaceColor to white if that is what you mean by transparent. Otherwise you could set the FaceAlpha to zero for the patch to be transparent.
Please accept an answer if it helps you.

3 comentarios

Due to round-off error, it is best not do do exact comparisons of floating point values.
patchesToHide = abs(patchValues - valueToHide) < 100*eps(valueToHide);
Arnault
Arnault el 28 de En. de 2013
Thanks, works well!
Arnault
Arnault el 28 de En. de 2013
Editada: Arnault el 28 de En. de 2013
I have a related question. The colorbar keeps the original color. Any idea on how I could do the same on the colorbar?

Iniciar sesión para comentar.

Más respuestas (2)

Will Grant
Will Grant el 31 de Ag. de 2021
Editada: Will Grant el 31 de Ag. de 2021

1 voto

See my answer here - working for R2020a
Leslie
Leslie el 3 de Feb. de 2015

0 votos

This solution has stopped working in 2014b. Does anyone know if we still change the tranparency of 2D contour plots? If so how? Thanks

1 comentario

Boris Belousov
Boris Belousov el 25 de Feb. de 2016
Editada: Boris Belousov el 25 de Feb. de 2016
Unfortunately you have to manually define a contour of the area you want to make transparent. See how to make contour plots transparent.

Iniciar sesión para comentar.

Categorías

Más información sobre Contour Plots en Centro de ayuda y File Exchange.

Preguntada:

el 28 de En. de 2013

Editada:

el 31 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by