Highlight a specific contour level in contour plot?

Hi,
I have a contour plot and I want to highlight only a selected contour level. How can I do it? I tried all techniques reported but no success.
my code is follows and I want to highlight contour only with levels equal to 0 (zero). Can anyone help me out. Thank you. I am using matlab2015a.
z=load('data.txt');z=round(z);
x=1:0.1:9.1;
y=80:0.5:115;
[C,h] = contourf(x,y,x);
colorbar;
thisH = findall(h,'Userdata',0.0);
set(thisH,'linewidth',5)

 채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 2월 2일
The simplest way might just be to add an separate contour:
[C,h] = contourf(peaks(123));
hold on
emphasis_level = 0;
contour(peaks(123),[1 1]*emphasis_level,'k','linewidth',2);
HTH

댓글 수: 6

Thank you
Sorry, I thought it worked but when I tried with a simple example it didn't. for example, I want to highlight levels with zeros. here is the code.
M=[1 2 3;4 5 6;0 0 0;1 1 1; 2 2 2;0 1 0];
X=1:3;Y=1:6;
[c,h]=contourf(X,Y,M);
hold on;
emphasis_level = 0;
contour(X,Y,M,[1 1]*emphasis_level,'r','linewidth',1.5);
That is because you will get no contours at zero in your example, that is another problem more related to the contouring-algorithm and intensities at the extrema of the data range. If you try:
M=[1 2 3;4 5 6;0 0 0;1 1 1; 2 2 2;0 1 0];
X=1:3;Y=1:6;
[c,h]=contourf(X,Y,M-1);
hold on;
emphasis_level = 0;
contour(X,Y,M-1,[1 1]*emphasis_level,'r','linewidth',1.5);
Okay..I checked the data manually and, to me, it feels like the first code (your first response) is taking values less than or equal to zeros in the contour plot. Becasue I am getting the areas with red boundaries at some regions with non-zero values (but with negative values). Or is it problem with the number of contour levels?
Bjorn Gustavsson
Bjorn Gustavsson 2021년 2월 2일
편집: Bjorn Gustavsson 2021년 2월 2일
Yes. In my first example peaks has values safely above and below zero. In your example M has extreme-values exactly at zero. Then you will just not get a contour at that level, it might be a requirement that M has values above and below a contour-level to actually make a contour, think about this the way of a topographic map, for a contour to be meaningfull the topography has to be above that level on one side and lower on the other. My interpretation is that the reason you get no contour just at zero in your example is an unrelated problem to the highlighting question.
got it..thank u..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

질문:

2021년 2월 2일

댓글:

2021년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by