Summary
The UnclassedColorsRenderer class draws quantities using an unclassed color gradient.
Discussion
The properties behave in a similar manner to the options exposed in the application. For example, changing the field will automatically adjust the upper and lower labels. If you change expression, the field automatically changes to Custom.
Properties
Property | Explanation | Data Type |
colorRamp (Read and Write) | Provides access to the ColorRamp object. | ColorRamp |
expression (Read and Write) | A string that represents a valid SQL expression. When an expression is applied, the field name in the Symbology pane appears as Custom. | String |
field (Read and Write) | A string that represents a valid, numerically defined field name used for setting unclassed colors. A value of None is possible, but it must be changed to a valid field name for the renderer to display properly. | String |
lowerLabel (Read and Write) | A string that represents the lower label that appears in the Contents pane or legend. | String |
normalizationField (Read and Write) | A string that represents a valid numerically defined field name that is used for normalization. | String |
symbolTemplate (Read Only) | Returns a symbol that represents the symbol template for all the features in the layer. To set the template, use the updateSymbolTemplate method. | Symbol |
type (Read Only) | Returns a string that represents the renderer type. | String |
upperLabel (Read and Write) | A string that represents the upper label that appears in the Contents pane or legend. | String |
Method Overview
Method | Explanation |
updateSymbolTemplate (symbol_template) | updateSymbolTemplate provides a mechanism to change the renderer's symbol template. |
Methods
updateSymbolTemplate (symbol_template)
Parameter | Explanation | Data Type |
symbol_template | A reference to a symbol. (The default value is None) | Object |
The updateSymbolTemplate method allows you to modify the symbol for all the features at once. The symbol template is managed in the application differently and therefore requires a method to set the symbol template to the renderer.
Code sample
The following script first tests whether the layer's symbology supports a renderer property. It then confirms whether the renderer type is an UnclassedColorsRenderer. Next, it modifies basic properties such as fields and labels. Next, it applies a system ColorRamp named Yellow to Red. Finally, it modifies the symbolTemplate using a gallery symbol named Black Outline (1pt).
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('UnclassedColors')[0]
l = m.listLayers('States_WithRegions')[0]
if l.isFeatureLayer:
sym = l.symbology
if hasattr(sym, 'renderer'):
if sym.renderer.type == 'UnclassedColorsRenderer':
#modify basic properties
sym.renderer.field = "POP2010"
sym.renderer.normalizationField = "Shape_Area"
sym.renderer.lowerLabel = "Upper: " + sym.renderer.lowerLabel
sym.renderer.upperLabel = "Lower: " + sym.renderer.upperLabel
#Modify color ramp
cr = p.listColorRamps('Yellow to Red')[0]
sym.renderer.colorRamp = cr
#Modify the symbol template
symTemp = sym.renderer.symbolTemplate
symTemp.applySymbolFromGallery('Black Outline (1pt)')
sym.renderer.updateSymbolTemplate(symTemp)
l.symbology = sym