How to get a specific shape of a contour plot in MATLAB

122 Views Asked by At

How can I get a specific shape of a contour plot in MATLAB? I have plotted this figure using the MATLAB contourf(x,y,z) function, where x and y are the vectors and Z is a matrix. How can only I get the Lower triangle?

Thank you

1

There are 1 best solutions below

0
Renato Bichara Vieira On

You need to make the values of z = NaN at the locations you don´t want to plot. This example code might help you:

step = 0.1;
x = 0:step:100;
y = 0:step:100;

z1 = peaks(length(x));
z2 = peaks(length(x));
for i = 1 : length(x)
    for j = 1 : length(x)
        if (i>length(x)-j)
            z2(i,j) = NaN;
        end
    end
end

fig = figure;
subplot(1,2,1)
%produces whole image
contour(x,y,z1,10);
subplot(1,2,2)
%produces only a triangle
contour(x,y,z2,10);

enter image description here