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 个评论

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
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')
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!

Translated by