I'm using ArcMap 10.3. In symbology, there are 6 decimal digits for the different classes of the variable I'm presenting. I'd like to show only 3 decimal digits. I can edit the label and change the decimals manually for each class. Is there any faster way to do this for all classes in ArcMap 10.3?
Answer
You can accomplish this with the arcpy.mapping
module. The following should work as long as your symbology is GraduatedColorsSymbology
. Just paste into the python window and run the function with your layer name and number of decimal places. Since it's using Python's built-in round()
function, you can even use negative numbers.
def trunclabels(lyrname, n):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, lyrname, df)[0]
labels = lyr.symbology.classBreakLabels
#split the labels, cast to float, round, then join back together
lyr.symbology.classBreakLabels = ["{} - {}".format(*r)
for r in [[round(float(f), n)
for f in lab.split(" - ")]
for lab in labels]]
arcpy.RefreshTOC()
del mxd, df
No comments:
Post a Comment