Generate a point/marker on a filled contour

3 views (last 30 days)
Hello,
I want to highlight the maximum value of a filled contour, but with the code that I wrote the marker/point won't come up or it shows up outside of the image when I use OpenGL as renderer.
The data for the code is an array A, with the dimension:[361x181] which represents the radiation of the sun at any given angle and orientation. The code should find the indices of the highest value and then plot that point over the filled contour. But I just can't seem to find the flaw in my code as Matlab doesn't give an error message.
Thanks for your answers,
Roland
B=circshift(A, [0, 1]);
set(gcf,'renderer','zbuffer');
[th,r] = meshgrid((1:361)*pi/180,1:181);
[X,Y] = pol2cart(th,r);
h = polar([0 2*pi], [0 180]);
delete(h);
ph=findall(gca,'type','patch');
set(ph,'facecolor','none','edgecolor', 'none','linewidth',1);
hold on;
contourf(X,Y,B,200),shading flat;
[r,c]=find(B==max(max(A)));
plot(r,c,'.w', 'markersize', 30);
view([90 -270]);

Accepted Answer

Image Analyst
Image Analyst on 27 Mar 2012
Roland, you didn't quite do your r,c code right. Try this:
s = load('C:\Users\Me\Documents\Temporary\Euit-1965 januari.mat')
A = s.A;
B=circshift(A, [0, 1]);
[rows columns] = size(B)
set(gcf,'renderer','zbuffer');
[th,r] = meshgrid((1:361)*pi/180,1:181);
[X,Y] = pol2cart(th,r);
h = polar([0 2*pi], [0 180]);
delete(h);
ph=findall(gca,'type','patch');
set(ph,'facecolor','none','edgecolor', 'none','linewidth',1);
hold on;
contourf(X,Y,B,200);
shading flat;
[maxValue linearIndexAtMax] = max(B(:))
[thetaAtMax, rhoAtMax] = ind2sub([rows columns], linearIndexAtMax)
hold on;
plot(thetaAtMax, rhoAtMax-360, 'w+', 'MarkerSize', 30, 'LineWidth', 3);
colorbar;
view([90 -270]);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
  1 Comment
Roland
Roland on 27 Mar 2012
Thank you, that did the trick, at least for these files.
But it's really strange because these files represent the months January and June, but your code doesn't work on file representing a full year. Now here the strange part: For a full year, I got the old code working... and these files are in layout the same but the data is a factor 10-100 higher than for a month. Should that make any difference?
So it works, but I don't understand why not all the files. But I got my markers and that is what matters, thank you very much.
files of a full year:
http://dl.dropbox.com/u/33717684/Euit-1964%20heel%20jaar.mat
http://dl.dropbox.com/u/33717684/Euit-1965%20heel%20jaar.mat

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 26 Mar 2012
Plot the point slightly above (Z axis) where you want to show up, using plot3().
When you mix lines and surfaces at the same Z depth, then OpenGL has its own ideas about which should show up on top, and some of the graphics drivers get the order exactly reversed. Easiest way to be sure: tweak the Z depths to get the order you want.

Roland
Roland on 26 Mar 2012
Hello Walter,
At first, thank you for the quick reply.
Plot3() doesn't seem to work, but that could be just me, because I'm really new at Matlab. This is how I used it: plot3(r,c,z); instead of plot(r,c,'.w', 'markersize', 30);
For Z I used some different numbers, ...-1 0 1... etc. And the marker size was set manually. With the opengl renderer I got a datapoint, but yet again outside of the plot area (I've attached a picture in the link below). The other two renderers showed the same position using the Plot Browser, but there was nothing to see.
Could this be an issue with the polar plot?
Roland

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!