Colors above a level is not shown in a contour plot
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1243332/image.png)
This is my image and i want to draw boundaries to the clusters.
contourf(z_test_img, 40, 'EdgeColor','none'), colormap jet, colorbar
hold on
contourf(z_test_img, [z_thresh, z_thresh])
hold off
This was my attempt to add both the image with bıth contour lines and without contour lines in the same plot, and it works. But, with an issue, which is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1243337/image.png)
It shows the boundaries but the colors above level 2 stays the same. I couldn't figure it out on how to solve it. Any ideas?
0 comentarios
Respuestas (2)
KSSV
el 26 de Dic. de 2022
[X,Y,Z] = peaks(100) ;
[c,h] = contour(X,Y,Z,[6 6]) ;
% arrange the contour
c(:,1) = NaN ;
% plot
contourf(X,Y,Z,'EdgeColor','none') ; shading interp ; colorbar ; colormap(jet) ;
hold on
plot(c(1,:),c(2,:),'k')
3 comentarios
KSSV
el 26 de Dic. de 2022
Editada: KSSV
el 26 de Dic. de 2022
You need to remove the outliers in c....either attach your data or remove the outliers by replacing them with NaN.
[X,Y,Z] = peaks(100) ;
[c,h] = contour(X,Y,Z,[4 8]) ;
% arrange the contour
idx = isoutlier(c(1,:)) ;
c(:,idx) = NaN ;
% plot
contourf(X,Y,Z,'EdgeColor','none') ; shading interp ; colorbar ; colormap(jet) ;
hold on
plot(c(1,:),c(2,:),'k')
Star Strider
el 26 de Dic. de 2022
The straight lines connecting the contours are because of the way the contour matrix (‘M’ here) are formatted.
Do something like this —
[X,Y,Z] = peaks;
figure
[M,C] = contourf(X, Y, Z, 'ShowText',1);
Levels = C.LevelList
for k = 1:numel(Levels) % Get Contour (x,y) Coordinates For Each Contour Level
idx = find(M(1,:) == Levels(k));
ValidV = rem(M(2,idx),1) == 0;
StartIdx{k,:} = idx(ValidV);
VLen{k,:} = M(2,StartIdx{k});
end
figure
hold on
k1 = 4; % Choose The '-2' Contour (Levels(4))
% for k1 = 1:numel(Levels)
for k2 = 1:numel(StartIdx{k1})
idxv = StartIdx{k1}(k2)+1 : StartIdx{k1}(k2)+VLen{k1}(k2); % Index For Contour 'k1'
xv = M(1,idxv);
yv = M(2,idxv);
plot(xv, yv)
end
% end
hold off
axis([-3 3 -3 3])
title('Contours At The ‘-2’ Level')
.
0 comentarios
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!