Re: Generate an N-color colormap using an existing colormap

From: Rick Brownrigg <brownrig_at_nyahnyahspammersnyahnyah>
Date: Fri Feb 01 2013 - 15:54:18 MST

Hi John,

This is untested, but I think somthing like this should work; where N is the size of the color table, and M the number of new colors:

do i=0,M-1
    percent = integertofloat(i) * N / M ; coerce to a floating-point result
    index = floor(percent)
    weight = percent - index
    newCMap(i,:) = oldCMap(index+1,:)*weight + oldCMap(index,:)*(1-weight)
end do

For the i-th entry in your new cmap, this tries to find which colors in the old cmap it falls between, and interpolates between the two. You might need to divide by (M-1) to calculate the variable percent if you want the end points of your original cmap to appear in the new cmap (?)

Hope that helps…
Rick

On Feb 1, 2013, at 12:30 PM, John Kerfoot <johnkerfoot@gmail.com> wrote:

> Hello,
>
> I'd like to scatter some polymarkers over a map and color-code the markers based on their values. Ideally, I'd like to read in an existing colormap using the read_colormap_file NCL function and then linearly interpolate through each of the RGB arrays to create a new colormap with an arbitrary number of levels (corresponding to the bins I set up using the data).
>
> For example, let's say I have some data and want to color code the values as a percentage where my percentage bins are:
>
> 0 - 9%
> 10 - 19%
> 20 - 29%
> 30 - 39%
> 40 - 49%
> 50 - 59%
> 60 - 69%
> 70 - 79%
> 80 - 89%
> >= 90%
>
> That's 10 levels.
>
> If I read in an exising NCL colormap, say helix, which has 256 colors, I'd like to interpolate through each of the RGB channels and end up with 10 colors that I can use to color my markers depending on which bin they fall into.
>
> How would I go about achieving this, keeping in mind that my number of levels will change with the dataset I'm plotting?
>
> Thanks,
> John
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Feb 1 15:54:24 2013

This archive was generated by hypermail 2.1.8 : Wed Feb 06 2013 - 16:37:01 MST