Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: colors for contour plots
Date: Wed, 23 Sep 2009 11:58:06 +0000 (UTC)
Organization: Laboratoire de Biomecanique-CHU Purpan
Lines: 33
Message-ID: <h9d2gd$76h$1@fred.mathworks.com>
References: <h9ch1n$121$1@fred.mathworks.com> <h9cs40$6up$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1253707086 7377 172.30.248.37 (23 Sep 2009 11:58:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Sep 2009 11:58:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 492531
Xref: news.mathworks.com comp.soft-sys.matlab:572303


> As far as I know, you can only change the contour fill colour afterwards, not specify it while plotting.
> ...
> Sebastiaan

The same solution but with a colormap :

figure

map = [1 0 0
       0 1 0
       0 0 1
       0 1 1];
   
colormap(map);

[C,h] = contourf(peaks(20));
Cld = get(h, 'Children');
for j=1:length(Cld)
    if strcmp(get(Cld(j), 'Type'), 'patch')
        Iso = get(Cld(j), 'CData');
        if Iso<-5
            set(Cld(j), 'cdata', 0);
        elseif Iso>=-5 && Iso<0
            set(Cld(j), 'cdata', 1);
        elseif Iso>=0 && Iso<5
            set(Cld(j), 'cdata', 2);
        else
            set(Cld(j), 'cdata', 3);
        end
    end
end

Jerome