Symbolize a single band image with a multi-color ramp

Last Published: April 25, 2020


This article provides a script that applies a multi-color ramp to single-band image.


  1. Open a new script.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Paste the following script into the script window:

    '-- The following script applies a "red to blue to white"
    '-- color ramp to a single band image legend.
    '-- It assumes that the active doc is a view and that
    '-- one and only one theme is active in that view and that the
    ' active theme is an image theme with a single band image legend.

    theView = av.GetActiveDoc
    theTheme = theView.GetActiveThemes.Get(0)
    theLegend = theTheme.GetLegend

    '-- Get the color map from the image legend. This is easiest.
    '-- You can create a new color map using ColorMap.MakeRandom,
    '-- ColorMap.MakeNominal, or any of the ColorMap.Make* request.
    '-- It doesn't really matter which one you use as long as
    '-- you set the size to 256. If you make a new color map
    '-- then before theTheme.UpdateLegend you need to do
    '-- theLegend.SetColorMap(newColorMap)

    theColorMap = theLegend.GetColorMap

    '-- Create a red to blue color map and a blue to white
    '-- color map each with 128 colors

    redBlueColorMap = ColorMap.MakeRamp(128,Color.GetRed,Color.GetBlue)
    blueWhiteColorMap = ColorMap.MakeRamp(128,Color.GetBlue,Color.GetWhite)

    '-- Use the two new 128 color maps to apply colors
    '-- to the original 256 color map or a new 256 color map.

    for each i in 0..127
    for each i in 128..255

    '-- Update the legend and redraw theme.


    '-- You can set a lookup if needed. For example, your image
    '-- data went from 0 to 100 and you wanted to stretch
    '-- that data across the entire color map. The following
    '-- two lines of code will do this. Place these two lines
    ' before theTheme.UpdateLegend above.
    'newLookup = LinearLookup.MakeLine(Point.Make(0,0),Point.Make(100,255))

    '-- It is best to start from the current image legend of an image theme,
    '-- but you can start from scratch. The code below does this.
    '-- Instead of theTheme.UpdateLegend above you would
    '-- use theTheme.SetLegend(newLegend). It is best to set a
    '-- color map of 256 colors.
    'anImageLookup = LinearLookup.MakeLine(Point.Make(0,0),Point.Make(255,255))
    'aColorMap = ColorMap.MakeRamp(256,Color.GetYellow,Color.GetBlue)
    'newLegend = SingleBandLegend.Make(0,anImageLookup,aColorMap)
    '-- The above lookup is the same as the identify lookup,
    '-- or IdentityLookup.Make. It maps the values in the image
    '-- to the same value in the color map.

  3. Compile and run the script.

    A. Click the Compile button.
    [O-Image] Script compile button

    B. Click the Run button.
    [O-Image] Run compiled script button

Article ID:000003964

  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic