HOW TO

Set a graduated colors renderer with manual intervals in ArcGIS Pro using Python

Last Published: April 25, 2020

Summary

Graduated colors symbology is used to show a quantitative difference between mapped features by varying the color of symbols. Data is classified into ranges that are each assigned a different color from a color scheme to represent the range. Refer to ArcGIS Pro: Graduated colors for more information.

It is possible to set a graduated colors renderer using the ArcPy module through the GraduatedColorsRenderer class.

Procedure

The following steps describe how to set a graduated colors renderer using the ArcPy module:

  1. Import the necessary modules.
import arcpy
  1. Create the parameter to specify the current project and maps.
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps("Map")[0]
lyr = m.listLayers()[0]
sym = lyr.symbology
  1. Run the function to use the GraduatedColorsRenderer class and the color specification.
sym.updateRenderer("GraduatedColorsRenderer")
sym.renderer.colorRamp=p.listColorRamps("Cyan to Purple")[0]
  1. Create the parameters to set the value intervals.
classBreakValues = [25000,150000,1000000,3000000,10000000]
classBreakLabels = ["div 1", "div 2", "div 3", "div 4", "div 5"]
  1. Run the renderer.breakCount function to use the classBreakValues array parameters as the values, and create a counter.
sym.renderer.breakCount = len(classBreakValues)
count = 0
  1. Create a loop to set the renderer.
for brk in sym.renderer.classBreaks:
    brk.upperBound = classBreakValues[count]
    brk.label = classBreakLabels[count]
    count += 1
lyr.symbology = sym

The following shows the full script:

import arcpy

p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps("Map")[0]
lyr = m.listLayers()[0]
sym = lyr.symbology

sym.updateRenderer("GraduatedColorsRenderer")
sym.renderer.colorRamp=p.listColorRamps("Cyan to Purple")[0]

classBreakValues = [25000,150000,1000000,3000000,10000000]
classBreakLabels = ["div 1", "div 2", "div 3", "div 4", "div 5"]

sym.renderer.breakCount = len(classBreakValues)
count = 0

for brk in sym.renderer.classBreaks:
    brk.upperBound = classBreakValues[count]
    brk.label = classBreakLabels[count]
    count += 1
lyr.symbology = sym

Article ID: 000020468

Software:
  • ArcGIS Pro

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options