GraduatedColorsRenderer

概要

The GraduatedColorsRenderer class represents the graduated color renderer definition that shows qualitative differences in feature values using a range of color.

ディスカッション

The properties behave in a similar manner to the options exposed in the application. For example, changing the number of classes will automatically adjust the break values and their labels. If you change upperBound of a ClassBreak, the classificationMethod automatically changes to ManualInterval. You also need to manually update the labels and/or descriptions accordingly.

プロパティ

プロパティ説明データ タイプ
breakCount
(読み書き)

An integer that represents the number of classes to be used with the current classification method.

Integer
classBreaks
(読み書き)

A list of ClassBreak objects that provides access to individual properties such as label and description as well as individual symbol objects.

List
classificationField
(読み書き)

A string that represents a valid field name used for the layer's classification method.

String
classificationMethod
(読み書き)

A string that represents a valid classification method. The valid values are as follows:

  • DefinedIntervalDefined Interval
  • EqualIntervalEqual Interval
  • GeometricIntervalGeometric Interval
  • ManualIntervalManual Interval
  • NaturalBreaksNatural Breaks (Jenks)
  • QuantileQuantile
  • StandardDeviationStandard Deviation
String
colorRamp
(読み書き)

Provides access to the ColorRamp object.

ColorRamp
deviationInterval
(読み書き)

A double that represents a valid deviation interval that is only available if classificationMethod is set to StandardDeviation. Valid values are 1.0, 0.5, 0.333, and 0.25. These are the same options available in the application.

Double
intervalSize
(読み書き)

A double that represents an interval size that is only available if classificationMethod is set to DefinedInterval.

Double
normalizationField
(読み書き)

A string that represents a valid layer field name that is used for normalization.

String
normalizationType
(読み書き)

A specific string that represents a valid normalization key word. For example, to clear the normalization, try gradColors.renderer.nomalizationType = "<None>".

  • <None>No normalization
  • <percentage of total>Percentage of total
  • <log>Log
String
type
(読み取り専用)

Returns a string that represents the renderer type.

String

コードのサンプル

GraduatedColorsRenderer example 1

The following script first tests if the layer's symbology supports a renderer property and then confirms if the renderer is a SimpleSymbolRenderer. Next is changes the renderer to aGraduatedColorsRenderer and it changes the classificationField and breakCount. Finally, it changes ColorRamp to a color ramp named Cyan to Purple.

import arcpy, os, sys

relpath = os.path.dirname(sys.argv[0])

p = arcpy.mp.ArcGISProject(relpath + r'\\GraduatedColors.aprx')
m = p.listMaps('Layers')[0]
l = m.listLayers('State*')[0]
sym = l.symbology

if hasattr(sym, 'renderer'):
  if sym.renderer.type == 'SimpleRenderer':
    sym.updateRenderer('GraduatedColorsRenderer')
    sym.renderer.classificationField = 'Shape_Area'
    sym.renderer.breakCount = 10
    sym.renderer.colorRamp = p.listColorRamps('Cyan to Purple')[0]

    l.symbology = sym

p.saveACopy(relpath + r'\\SavedOutput.aprx')
GraduatedColorsRenderer example 2

The following script modifies the symbology of a polygon layer that uses a graduate color renderer. It sets the classificationField and breakCount and iterates through each class break and modifies the upperBound, label, description, and symbol properties such as color, outlineColor, and size. The labels for each break are formatted to include thousands separators. The fill color graduates from red to blue, and the outline color goes from blue to red and increases in size with each break.

# -*- coding: utf-8 -*-
import arcpy, os, sys, locale

relpath = os.path.dirname(sys.argv[0])

p = arcpy.mp.ArcGISProject(relpath + r"\\GraduatedColors.aprx")
m = p.listMaps("Layers")[0]
l = m.listLayers("Natural*")[0]

sym = l.symbology
sym.renderer.classificationField = "Shape_Area"
sym.renderer.breakCount = 7

breakVal = 100000000000
cv = 0
lw = 1
for brk in sym.renderer.classBreaks:
  brk.upperBound = breakVal
  brk.label = "\u2264" + str(locale.format("%d", breakVal, grouping=True))
  brk.description = "Description " + str(cv)
  brk.symbol.color = {'HSV' : [cv, 100, 100, 100]}
  brk.symbol.outlineColor = {'HSV' : [240-cv, 100, 100, 100]}
  brk.symbol.size = lw

  breakVal +=100000000000
  cv += 40
  lw += 0.5
l.symbology = sym

p.saveACopy(relpath + r'\\SavedOutput.aprx')