Discussion:
Adding markers to a contour plot
(too old to reply)
Jason
2012-03-05 17:25:12 UTC
Permalink
Is there a way to add markers to a contour plot, or alternatively, to easily save a particular contour level as an XY data set and plot it using plot()?

What I am trying to do is:
figure
contour(X1, Y1, Z1, contour_level, '-k');
hold on
contour(X1(1:3:end), Y1(1:3:end), Z1(1:3:end,1:3:end), contour_level, '^k');
contour(X2, Y2, Z2, contour_level, '-r');
contour(X2(1:3:end), Y2(1:3:end), Z2(1:3:end,1:3:end), contour_level, 'or');
contour(X3, Y3, Z3, contour_level, '-b');
hold off

The intention is to plot 3 contours on top of one another and differentiate them with markers and colour (so that the lines may still be differentiated if printed in B&W). Simply changing the linestyles does not change their visual appears enough.

There are two problems with the above method:
(1) Marker calls are disabled for contour().
(2) When plotting the undersampled contours (e.g. X1(1:3:end)), which was originally intended to put one marker per every 3 data points on a line, it actually recalculates the contours and shifts them (presumably because the contour is different for the undersampled case).

Is there any easy work-around and/or an simple way to just save my contours into an XY format so that I can plot them with plot()?

Thank you.
matt dash
2012-03-05 17:44:10 UTC
Permalink
Post by Jason
Is there a way to add markers to a contour plot, or alternatively, to easily save a particular contour level as an XY data set and plot it using plot()?
figure
contour(X1, Y1, Z1, contour_level, '-k');
hold on
contour(X1(1:3:end), Y1(1:3:end), Z1(1:3:end,1:3:end), contour_level, '^k');
contour(X2, Y2, Z2, contour_level, '-r');
contour(X2(1:3:end), Y2(1:3:end), Z2(1:3:end,1:3:end), contour_level, 'or');
contour(X3, Y3, Z3, contour_level, '-b');
hold off
The intention is to plot 3 contours on top of one another and differentiate them with markers and colour (so that the lines may still be differentiated if printed in B&W). Simply changing the linestyles does not change their visual appears enough.
(1) Marker calls are disabled for contour().
(2) When plotting the undersampled contours (e.g. X1(1:3:end)), which was originally intended to put one marker per every 3 data points on a line, it actually recalculates the contours and shifts them (presumably because the contour is different for the undersampled case).
Is there any easy work-around and/or an simple way to just save my contours into an XY format so that I can plot them with plot()?
Thank you.
[c,h]=contour(X,Y,Z)
k=get(h,'children')
set(k,'marker','s')

c is a matrix that contains the x/y data. read the help for contourc to see how to interpret this. h is an hggroup, i.e. a group of all the contours. k are the individual contours, which are patches. You can just loop through k and set unique properties for each one.
Loading...