Hello,
I am unable to set the BreakCount for 'ManualInterval' symbology. The value remains zero. What is the proper way to set the number of breaks?
It works for 'NaturalBreaks' classificationMethod but not for 'ManualInterval'. Changing the classification method in the code below and removing the references to classBreaks will work as expected.
#ArcGIS Pro 2.1.2
#Python 3.6.2, 64 bit
aprx = arcpy.mp.ArcGISProject('CURRENT')
cwd = 'c:\\temp'
workingLayer = aprx.listMaps()[0].listLayers()[0]
sourceTable = arcpy.ListTables()[0]
sourceLayout = aprx.listLayouts()[0]
metric = ('Calc01Perc',(-0.5,0.5)) # (Field name, (min,max values))
sym = workingLayer.symbology
sym.updateRenderer('GraduatedColorsRenderer')
sym.renderer.classificationMethod = 'ManualInterval'
sym.renderer.classificationField = sourceTable + '_' + metric[0]
print('DEBUG fieldname: ' + sym.renderer.classificationField)
sym.renderer.colorRamp = aprx.listColorRamps('Bathymetric Scale')[0]
sym.renderer.breakCount = 10 # This does not stick for 'ManualInterval' or unspecified classificationMethod
print('DEBUG breakCount: ' + str(sym.renderer.breakCount) + '= 10 ?')
step = 0.1
breakVal = -0.5
print('DEBUG len(classBreaks) = ' + str(len(sym.renderer.classBreaks)))
for brk in sym.renderer.classBreaks:
brk.upperBound = breakVal
breakVal += step
print('DEBUG next break: ' + str(breakVal))
workingLayer.symbology = sym
Solved! Go to Solution.
OK, I figured it out.
Selecting the Manual Interval classification does not do anything. I suppose you can read it, but you cannot set it. So, per the documentation, to manually set class breaks, you must start with one of the standard classifications and make adjustments as needed.
In the code below, I set the classification method to equal interval and set the number of desired breaks. I then overwrite each of the breaks.
aprx = arcpy.mp.ArcGISProject('CURRENT')
workingLayer = aprx.listMaps()[0].listLayers()[0]
fieldName = 'Shape_Area'
sym = workingLayer.symbology
sym.updateRenderer('GraduatedColorsRenderer')
sym.renderer.colorRamp = aprx.listColorRamps('Bathymetric Scale')[0]
sym.renderer.classificationMethod = 'EqualInterval'
sym.renderer.classificationField = fieldName
sym.renderer.breakCount = 10
y = 0.3
x = y/10.0
for brk in sym.renderer.classBreaks:
print(str(i) + ': ' + str(x))
brk.upperBound = x
brk.label = '\u2264' + str(round(x,3))
x = round(x + (y/10),3)
workingLayer.symbology = sym
OK, I figured it out.
Selecting the Manual Interval classification does not do anything. I suppose you can read it, but you cannot set it. So, per the documentation, to manually set class breaks, you must start with one of the standard classifications and make adjustments as needed.
In the code below, I set the classification method to equal interval and set the number of desired breaks. I then overwrite each of the breaks.
aprx = arcpy.mp.ArcGISProject('CURRENT')
workingLayer = aprx.listMaps()[0].listLayers()[0]
fieldName = 'Shape_Area'
sym = workingLayer.symbology
sym.updateRenderer('GraduatedColorsRenderer')
sym.renderer.colorRamp = aprx.listColorRamps('Bathymetric Scale')[0]
sym.renderer.classificationMethod = 'EqualInterval'
sym.renderer.classificationField = fieldName
sym.renderer.breakCount = 10
y = 0.3
x = y/10.0
for brk in sym.renderer.classBreaks:
print(str(i) + ': ' + str(x))
brk.upperBound = x
brk.label = '\u2264' + str(round(x,3))
x = round(x + (y/10),3)
workingLayer.symbology = sym