I'm trying to set the minimum and maximum values for a graduated color layer with a script tool. (This is a slightly more complicated piece of code)
Below is the code.
glyr=arcpy.GetParameterAsText(0)
glyrlist=glyr.split("\\")
glp=glyrlist[0]
lyr=glyrlist[-1]
aprx=arcpy.mp.ArcGISProject("CURRENT")
activelayout=aprx.activeView
mpflames=activelayout.listElements("MAPFRAME_ELEMENT")[0]
maps=mpflames.map
lays=maps.listLayers(lyr)
for ly in lays:
if "\\" in ly.longName:
if ly.longName.split("\\")[0]==glp:
l=ly
else:
l=ly
sym=l.symbology
if hasattr(sym,'renderer'):
if sym.renderer.type=="GraduatedColorsRenderer" or sym.renderer.type == "GraduatedSymbolsRenderer":
#min
l_cim=l.getDefinition('V3')
l_cim.renderer.minimumBreak=-100000000
l.setDefinition(l_cim)
#max
sym=l.symbology
sym.renderer.classBreaks[-1].upperBound=100000000
l.symbology=sym
This code works as desired when you set up a layer with three or more classes.
However, when the number of classes is 2, the behavior becomes strange as shown in the figure. Also, at this time, if you change "100000000" on line 29 to "1000000", it will work properly.
Why does this happen?
The image below shows a slightly more complex code.
The color of the "3" square has changed.
I don't know the cause of this either.
Is there any way to solve it? thank you.