solid contour lines for some specific values of a contourf plot

After generating a contourf plot is it possible to draw a solid black line around some specific values?
For example:
[C,h] = contourf(peaks(20),10);
colormap autumn
From this, is it possible to dray a contour around the regions in the plot which correspond to values above a certain value, say 4. So, any values that are above 4 will have a solid black line surrounding it. How can this be achieved?

 採用された回答

Teja Muppirala
Teja Muppirala 2012 年 7 月 17 日
編集済み: Teja Muppirala 2012 年 7 月 17 日

0 投票

The userdata property of each patch is set to the level's value. You can use this to find the relevant patch, and make its line width bigger.
[C,h] = contourf(peaks(20),-10:10);
colormap autumn
thisH = findall(h,'Userdata',4.0);
set(thisH,'linewidth',3)
Redo (to make all levels above 4.0 bold):
[C,h] = contourf(peaks(20),10);
colormap autumn
kids = get(h,'children');
indices = cell2mat(get(kids,'Userdata')) > 4.0;
set(kids(indices),'linewidth',3)

3 件のコメント

Richard
Richard 2012 年 7 月 17 日
Doesn't this just dray a solid line for the values which are specifically 4.0? My values are not whole numbers i.e. all are decimal therefore I need a method which specifies the above but for values greater than 4.0.
So the problem from the above is that I do not have a value of 4.0 in my matrix, the values are e.g. 4.111, 4.l2313 etc.
Teja Muppirala
Teja Muppirala 2012 年 7 月 17 日
You have to look at all the patches and find the ones with userdata > 4.0. I updated the answer to reflect this.
Cva Shrestha
Cva Shrestha 2017 年 5 月 2 日
When i copied and ran the code..nochanges were observed..
when i checked the userdata was empty?? can anybody help in this

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Contour Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by