Hi,
Is there anyway to add markers to a contour plot? with a recent Matlab edition (i.e, 2017 and after)? My contour command looks something like that:
[x,y]=meshgrid(1:10,2:100):
% z is a matrix already predefined on the x and y levels
[c,h]=contour(x,y,z,levels)
When I add 'Marker' to the contour command specifications, I get the following error: unrecognized property Marker for class contour
Best,

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 29 日

0 投票

It is not possible with single call of contour(). You need to hold the axes and then make a seperate call to plot() or scatter(). For example
Z = peaks(100);
x = [20 50 40 90];
y = [45 23 10 78];
contour(Z)
hold on
plot(x, y, '+', 'LineWidth', 2, 'MarkerSize', 10)

8 件のコメント

Ahmad Zueter
Ahmad Zueter 2020 年 12 月 29 日
編集済み: Ahmad Zueter 2020 年 12 月 29 日
Thank you,
However, what I really want is to add the markers to the contour "Z".
From your code, I think the markers will go to the x,y plot, which seems to be independent from Z
Ameer Hamza
Ameer Hamza 2020 年 12 月 29 日
You mean you only have the Z values? In that case, how do you decide which Z value to mark if more than 1 points have the same Z value?
Ahmad Zueter
Ahmad Zueter 2020 年 12 月 29 日
Okay so basically I have a temperature distribution over an x-y domain. So basically my "Z" is the temperature. The temperature ranges beween -20 and 0 degrees. I wanna plot the -10 and -5 degrees contour with a different markers
Ahmad Zueter
Ahmad Zueter 2020 年 12 月 29 日
編集済み: Ahmad Zueter 2020 年 12 月 29 日
okay got it no worries thanks a lot!
Well the idea is after the line
[c,h]=contour(x,y,z,levels)
then you can get the x-y plotting data from the variable c. After that, you can use the normal "plot" command which accepts the "Marker" property
plot(c(:,1),c(:,2),'o')
Ameer Hamza
Ameer Hamza 2020 年 12 月 29 日
編集済み: Ameer Hamza 2020 年 12 月 29 日
Since there are several points with same Z values, following shows how you can find them and then use plot() to draw them with markers
Z = peaks(100);
levels = [-4 6];
c = contourc(Z, levels);
C = cell(size(levels));
for i = 1:numel(levels)
n = c(2,1);
C{i} = c(:,2:n+1);
c(:,1:n+1) = [];
end
contour(Z);
hold on
for i = 1:numel(levels)
plot(C{i}(1,:), C{i}(2,:), '+', 'LineWidth', 2, 'MarkerSize', 10)
end
Ameer Hamza
Ameer Hamza 2020 年 12 月 29 日
Yes, as you already mentioned in your comment, the idea is the same. In my code, I just divided each level into different cells so that colors can be controlled.
Ahmad Zueter
Ahmad Zueter 2020 年 12 月 29 日
This is Great! Thank you a lot!
Ameer Hamza
Ameer Hamza 2020 年 12 月 29 日
I am glad to be of help!!!

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2020 年 12 月 29 日

コメント済み:

2020 年 12 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by