Add markers to a contour plot
显示 更早的评论
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,
采纳的回答
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
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
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?
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
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
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

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.
This is Great! Thank you a lot!
I am glad to be of help!!!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Contour Plots 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
