Adding transparency to a contour plot

221 views (last 30 days)
Rae Taylor-Burns
Rae Taylor-Burns on 1 Dec 2020
Answered: Priyanka Rai on 28 Dec 2020
I have a contour plot, and I am looking to set the transparency of my contour plot to another variable and I cant figure out how to do this:
% color contour map
a = [1,2,3,4,5]
b = [.1, .5, 1, 2. 10]
c = a'*b
[X,Y] = meshgrid(a,b)
h = contourf(X,Y,c)
% transparency map
d = [5,4,3,2,1]
e = [10, 5, 1, 0.5, 0.1]
f = d'*e
[U,V] = meshgrid(d,e)
i = contourf(V,U,f)
I want the transparency of h to be determined by i. I can't figure out how to make this happen. FaceAlpha, AlphaData, etc are not working for me. Any help would be much appreciated!!

Answers (2)

Michael on 18 Dec 2020
My understanding is that this isn't supported. In the past I have done a surface plot, changed the transparancy, and then changed the view to see it from above. Here is an example.
data = rand(100,100);
view([0 90])

Priyanka Rai
Priyanka Rai on 28 Dec 2020
mesh(___,Name,Value) specifies surface properties using one or more name-value pair arguments. For example, 'FaceAlpha',0.5 creates a semitransparent mesh plot. You can use this reference for further understanding: Mesh surface plot - MATLAB mesh (
You can control the transparency of an object using the alpha function or by setting properties of the object related to transparency. Some graphics objects support using a different transparency value for the faces versus the edges of the object. Refer this link for a detailed understanding of list of objects:
You could also refer to this article, which gives an understanding of how transparency options have changed over different MATLAB versions:



Community Treasure Hunt

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

Start Hunting!