Re: plotting continuos values in discrete colors

Hi Cicero-

Cicero Augusto Wollmane Zandona wrote:
> 
> Hi,
> 
> I have some radar values (float) that vary from 0 to 200 and I've plotted
> then using an Integer2DSet and mapping in RGB. The result is very fine.
> 
> But now I need to plot these values in a different way: They need to be
> divided in intervals (like from 20 to 30), and each interval has it's own
> RGB color (like 122, 255, 012).
> 
> I don't know if I need to set different maps or something like that. I
> would apreciate any help, sugestions or any example avalible.

We do this with our radar data by creating a table of RGB values
with colors corresponding to specific value ranges.  The key is to 
use the setRange method in ScalarMap to set the range of the RGB values.
So, in your case, you could do something like:

   float[][] myColorTable = new float[3][201];  // table for RGB
   for (int i = 0; i < 50; i++) {  // red for first 50 values
      myColorTable[0][i] = 1.0f;
      myColorTable[1][i] = 0.0f;
      myColorTable[2][i] = 0.0f;
   } 
   for (int i = 50; i < 100; i++) {  // green for next 50 values
      myColorTable[0][i] = 0.0f;
      myColorTable[1][i] = 1.0f;
      myColorTable[2][i] = 0.0f;
   } 
   for (int i = 100; i < 150; i++) {  // blue for next 50 values
      myColorTable[0][i] = 0.0f;
      myColorTable[1][i] = 0.0f;
      myColorTable[2][i] = 1.0f;
   } 
   for (int i = 150; i < 201; i++) {  // yellow for last 51 values
      myColorTable[0][i] = 1.0f;
      myColorTable[1][i] = 1.0f;
      myColorTable[2][i] = 0.0f;
   } 
   ScalarMap rgbMap = new ScalarMap(radarValues, Display.RGB);
   rgbMap.setRange(0,200);
   ColorControl rgbControl = (ColorControl) rgbMap.getControl();
   rgbControl.setTable(myColorTable);

The setRange will make sure that the values in the color table map
to the values in the data.  That way myColorTable[*][0] will map
to the 0 data value, myColorTable[*][1] maps to 1, etc.  Otherwise,
autoScaling will be in effect and if for a particular radar image
you only have values ranging from 25 to 190, the colorTable values
will be scaled to fit into that range.

Don
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************


  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: