I have a shapefile of a country with 50 fields. Each field contains values (-3 to 3) for a particular month. I would like to create a for loop that iterates through the fields, updates the map, uses a common symbology and exports to a PNG file.
The symbology I would like to use is one color per number. -3 = dark orange, -2 = light orange, -1 = light yellow, 0 = grey, 1 = light green, 2 = dark green, 3 = very dark green. I've assigned these colors to the layer in the .mxd, and created a .lyr.
So far, I have this:
import arcpy
mxd = arcpy.mapping.MapDocument(r'path/to/mxd')
shp = r'path/to/country_shapefile'
outdir = r'path/to/out/directory'
symbology = r'path/to/symbology.lyr'
df = arcpy.mapping.ListDataFrames(mxd)[0]
fields = [field.name for field in arcpy.ListFields(shp)]
fields = fields(17:len(fields) # I only need to display the data in fields 17 onwards
layer = arcpy.mapping.ListLayers(mxd, 'country')[0]
symbol = layer.symbology
for field in fields:
symbol.valueField = field
symbol.classValues = [-3,-2,-1,0,1,2,3] # The range of values in the symbology
arcpy.ApplySymbologyFromLayer_management(layer, symbology)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
arcpy.mapping.ExportToPNG(mxd, outdir+'\\'+field+".png")
---
When I try this, I get a map displaying the values in every field, but not with the correct symbology.