Trying to only fill certain contours in a contour3 plot

조회 수: 4 (최근 30일)
Nicholas Backhouse
Nicholas Backhouse 2018년 3월 20일
답변: Vedant Shah 2025년 3월 12일
I have a contour3 plot overlying a surf plot and I am trying to find a way to only fill between two of the contours and not the others
%surf plot
figure
surf(X,Y,Z)
colormap gray;
camlight headlight;
lighting flat
grid on
shading interp
view(0,90)
title('Map of the Island')
xlabel('Longditude')
ylabel('Latitude')
zlabel('Elevation')
c = colorbar;
hold on
%3d contour plot
contour3(X,Y,Z,[0.1 200,500,750,1000,1250,1500,1750,2000,2250,2500,2750,3000,3250,3500,3750,4000])
I'm trying to change just the colour between 200 and 500 red and leave the rest unfilled. Is there a way to do this? Or would it be better to set up some kind of subplot of the surf plot and change that red, if so, how would I do that?

답변 (1개)

Vedant Shah
Vedant Shah 2025년 3월 12일
To fill a specific colour between only two contours while leaving the others unfilled, specific contour levels can be defined, and properties such as color can be explicitly set using “contour3” function. The official MATLAB documentation provides further details and can be accessed using the following command:
web(fullfile(docroot, "/matlab/ref/contour3.html"))
To achieve the desired result, the following line can be incorporated into the code:
contour3(X,Y,Z,[200, 500], 'r', 'LineWidth', 2);
This method effectively highlights the area between the chosen contour levels using sample data, while keeping the other contours visible.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by