Global Index (short | long) | Local contents | Local Index (short | long)
greyshd(aray, level);
greyshd(x, lev) This function shades in areas where the function x is greater than the value 'lev'. Note that lev MUST be a scalar, so this isn't like contourf. This is all done for a map axis.
This function calls | |
---|---|
function greyshd(aray, level); if isscalar(level); level = level * ones(size(aray)); end; if size(aray) ~= size(level); error('Input aray and Level must be the same size'); end; if ~ismap(gca); error('This function works for map axes only. Try contorf for non-map axes.'); end global XAX YAX FRAME if (size(YAX,1)==1); YAX = YAX'; end; if (size(XAX,1)==1); XAX = XAX'; end; [xk, yk] = keep_var(FRAME, XAX, YAX); aray2 = aray > level; if (FRAME(2)-FRAME(1) == 360); aray2 = [aray2(yk,:) aray2(yk,1)]; XAX2 = [XAX; (XAX(1)+360)]; YAX2 = YAX(yk); else aray2 = aray2(yk,xk); XAX2 = XAX(xk); YAX2 = YAX(yk); end lev2 = .9 [nlat, nlon] = size(aray2); % Now, surround the matrix by low values so the contours are closed % (This is in case lev is near or equal to the minimum of aray) aray2 = [repmat(NaN,1,(nlon+2)) ; repmat(NaN,nlat,1) aray2 repmat(NaN,nlat,1) ;... repmat(NaN,1,(nlon+2))]; aind = find(isnan(aray2)); aray2(aind) = (lev2 - .1) * ones(size(aind)); XAX2 = [2*XAX2(1,:)-XAX2(2,:); XAX2; 2*XAX2(nlon,:)-XAX2(nlon-1,:)]; YAX2 = [2*YAX2(1,:)-YAX2(2,:); YAX2 ; 2*YAX2(nlat,:)-YAX(nlat-1,:)]; [CS, msg] = contours(XAX2, YAX2, aray2, [lev2 max(max(aray2+1))]); if ~isempty(msg); error(msg); end; % Find the indices of the curves in the c matrix, and get the % area of closed curves in order to draw patches correctly. This % shouldn't matter... might be able to delete this... ii = 1; ncurves = 0; I = []; Area=[]; while (ii < size(CS,2)), nl=CS(2,ii); ncurves = ncurves + 1; I(ncurves) = ii; xp=CS(1,ii+(1:nl)); % First patch yp=CS(2,ii+(1:nl)); Area(ncurves)=sum( diff(xp).*(yp(1:nl-1)+yp(2:nl))/2 ); ii = ii + nl + 1; end % Plot patches in order of decreasing size. This makes sure that % all the leves get drawn, not matter if we are going up a hill or % down into a hole. When going down we shift levels though, you can % tell whether we are going up or down by checking the sign of the % area (since curves are oriented so that the high side is always % the same side). Lowest curve is largest and encloses higher data % always. H=[]; [FA,IA]=sort(-abs(Area)); if ~isstr(get(gca,'color')), bg = get(gca,'color'); else bg = get(gcf,'color'); end colr = [.9 .9 .9]; for jj=IA, nl=CS(2,I(jj)); lev=CS(1,I(jj)); xp=CS(1,I(jj)+(1:nl)); yp=CS(2,I(jj)+(1:nl)); % if (sign(Area(jj)) ~= sign(Area(IA(1))) ), % kk=find(nv==lev); % if (kk>1+sum(nv<=minz)*(~draw_min)), % lev=nv(kk-1); % else % lev=NaN; % missing data section % end; % end; if (isfinite(lev)) H=[H;patchm(yp,xp,-1*lev,'facecolor',colr,'edgecolor',colr,'linestyle','-')]; else H=[H;patchm(yp,xp,lev,'facecolor',bg,'edgecolor',bg,'linestyle','-')]; end; end; numPatches = length(H); if numPatches>1 for i=1:numPatches set(H(i), 'faceoffsetfactor', 0, 'faceoffsetbias', (1e-3)+(numPatches-i)/(numPatches-1)/30); end end if nargout>0, % Return contour matrix for unfilled contours % cout=contours(x,y,z,nv); cout = CS; end