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,

 Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 29 Dez. 2020

0 Stimmen

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 Kommentare

Ahmad Zueter
Ahmad Zueter am 29 Dez. 2020
Bearbeitet: Ahmad Zueter am 29 Dez. 2020
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 am 29 Dez. 2020
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 am 29 Dez. 2020
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 am 29 Dez. 2020
Bearbeitet: Ahmad Zueter am 29 Dez. 2020
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 am 29 Dez. 2020
Bearbeitet: Ameer Hamza am 29 Dez. 2020
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 am 29 Dez. 2020
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 am 29 Dez. 2020
This is Great! Thank you a lot!
Ameer Hamza
Ameer Hamza am 29 Dez. 2020
I am glad to be of help!!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Contour Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by