How to make one contour transparent in contourf?

44 vues (au cours des 30 derniers jours)
Arnault
Arnault le 28 Jan 2013
Modifié(e) : Will Grant le 31 Août 2021
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

Réponse acceptée

José-Luis
José-Luis le 28 Jan 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 commentaires
Arnault
Arnault le 28 Jan 2013
Thanks, works well!
Arnault
Arnault le 28 Jan 2013
Modifié(e) : Arnault le 28 Jan 2013
I have a related question. The colorbar keeps the original color. Any idea on how I could do the same on the colorbar?

Connectez-vous pour commenter.

Plus de réponses (2)

Will Grant
Will Grant le 31 Août 2021
Modifié(e) : Will Grant le 31 Août 2021
See my answer here - working for R2020a

Leslie
Leslie le 3 Fév 2015
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 commentaire
Boris Belousov
Boris Belousov le 25 Fév 2016
Modifié(e) : Boris Belousov le 25 Fév 2016
Unfortunately you have to manually define a contour of the area you want to make transparent. See how to make contour plots transparent.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by