フィルターのクリア

Elevate a single isoline in a contour (2D) plot

29 ビュー (過去 30 日間)
Marc Jakobi
Marc Jakobi 2013 年 8 月 31 日
Hi.
I have a 2D contour plot in the form of
contour(x,y,z,'LevelStep',2,'Fill','on')
which gives me isolines varying between the values 22 and 48 (13 fill colours in between), with z depending on various input parameters.
What I am trying to do is colour ONE isoline of the value 34 black, while leaving all other lines uncoloured, recognizable only through the fill of the in between values. The contour is supposed to display cost ranges in dependence of two factors. The isoline with the value x represents the profitability limit (all lines with a higher value are not profitable.
Any help would be much appreciated!

採用された回答

Sven
Sven 2013 年 8 月 31 日
編集済み: Sven 2013 年 8 月 31 日
Hi Marc,
Is this what you're trying to do?
[x,y,z] = peaks;
z = z*10
figure
[c,h] = contour(x,y,z,'LevelStep',2,'Fill','on')
hold on
[c2,h2] = contour(x,y,z, [34 34], 'Color','k')
I think that since your first call to contour cannot guarantee that there will be a contour exactly at your chosen level of 34, it's probably a good idea to just superimpose another contour at that specific level.
You can adjust colours of your contour(s) via the handles returned in h and h2.
If instead you really want to adjust the colour of the original contours, then you can hack things a little as follows:
[x,y,z] = peaks;
z = z*10;
yourValue = 34;
clf
[c,h] = contour(x,y,z,'LevelStep',2,'Fill','on');
children = get(h,'Children');
for i=1:length(children)
if any(get(children(i),'FaceVertexCData')==yourValue)
set(children(i),'EdgeColor','k')
end
end
Did that help you out?
  3 件のコメント
Marc Jakobi
Marc Jakobi 2013 年 9 月 5 日
Hi Sven.
Do you know if it is possible to make the line dotted?
Marc
Sven
Sven 2013 年 9 月 5 日
Sure, there's a property of the resulting handle called 'LineStyle' that can be set to various styles (see the plot command for a list of styles):
[x,y,z] = peaks;
z = z*10;
figure
[c,h] = contour(x,y,z,'LevelStep',2,'Fill','on')
hold on
[c2,h2] = contour(x,y,z, [34 34], 'Color','k')
set(h2,'LineStyle',':')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by