How can I draw a contour line in contourf around "threshold" value

35 views (last 30 days)
Hi all, I am pretty new to Matlab and have the following problem: In my contourf plot I would really like to draw a contour line around areas that include values above a specified threshold value (in my case: 0.9999). I am visualizing simulated fidelities. Here is the code I use to generate my plots:
[C,h] = contourf(yplot, x, Zplot, 120);shading flat;%, 'LineStyle', 'none');shading flat;
kids = get(h,'children');
indices = cell2mat(get(kids,'Userdata')) > 0.8;
t = colorbar('location','EastOutside','CLim',[0.5,1]);
set(get(t,'ylabel'),'String','Treue $\Phi$','FontSize',20);
xlabel('Startwert \epsilon_0 [GHz]','FontName','Timesnewroman','FontSize',20);
And here is how the output looks like: The part with "kids = ..." etc is taken from a thread that deals with an almost identical question but somehow that does not work in my case. Just copying from the linked thread works fine, but not for my own plots...
I hope that I made an understandable description for my problem! I would really appreciate some help.
Thanks in advance, Luk
Edit: Just noticed a stupid mistake... The "shading flat" line seems to surpress the line(s) to be drawn. Nevertheless if I remove "shading flat" it seems that there is not enough precision to find values that are >0.999. But such values are definitely inside my Zplot matrix - as I can see by using max(Zplot). It is also confusing that my colorbar goes only to slightly over 0.95 even though I set its maximum to 1 as there are a lot more values above 0.95 which need to be distinguished precisely.

Answers (1)

Kuifeng on 11 Oct 2013
Edited: Kuifeng on 11 Oct 2013
contourf(X, Y, Data, [0.9999 0.9999] )
Quote "To display a single contour line at a particular value, define v as a two-element vector with both elements equal to the desired contour level. For example, to draw a single contour of level i, use contourf(Z,[i i])"
Option 2:
hold on
contourf(X, Y, Data, [0.9999 0.9999], 'linestyle', 'none')
contour(X, Y, Data, [0.9999 0.9999] , 'linecolor', 'k')

Community Treasure Hunt

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

Start Hunting!

Translated by