Select to view content in your preferred language

Format label field in symbology

2607
6
Jump to solution
12-29-2021 12:17 PM
Labels (1)
JohannaKraus2
Frequent Contributor

Symbology with multiple values automatically puts a comma and space between the two field values in the Value column, but in the Label column (which gets used in the legend) it only places a comma with no space:

JohannaKraus2_0-1640808662275.png

I can manually add in a space but I would like to be able to format all the records at once - ideally it would be great to change the comma to a dash or something else.  Is this possible somehow and I just can't find it?

 

0 Kudos
1 Solution

Accepted Solutions
Robert_LeClair
Esri Esteemed Contributor

Johanna - I know this is not the same thing but I think the logic is "yes, you can do this formatting with Python."  The Tech Article URL is here but you'd need to do some Python magic to make it work for your example. Any Python folks in this forum want to give it a go?

View solution in original post

6 Replies
Robert_LeClair
Esri Esteemed Contributor

Johanna - I know this is not the same thing but I think the logic is "yes, you can do this formatting with Python."  The Tech Article URL is here but you'd need to do some Python magic to make it work for your example. Any Python folks in this forum want to give it a go?

JohannaKraus2
Frequent Contributor

Yes, this is what I'm looking for - I'll give it a go.  Thank you!

0 Kudos
Jeremy_Z
Regular Contributor

Were you able to get a working solution? I've got a map I'm working on that needs updated monthly, and I'm using a second legend as a project key for active projects. It's almost perfect, but I need...

Field 1. Field 2

I've been trying to figure it out with the python code shared, but don't know what to change to finish this. Removing the , would probably be enough if I can figure out how to have the label be both fields with a period in it instead of a comma.

GIS - Getting it Surveyed is too expensive.
0 Kudos
SukhwinderSingh
Emerging Contributor

Yes, you can make it change. you can edit in excel, if you have this data in csv format. In excel go to "Text to columns". you can make all value in different columns and then you can apply symbology as you like.

0 Kudos
JohannaKraus2
Frequent Contributor

I'm not sure I understand this.  I don't see a way to export the label field from the symbology tab or import it back in.

0 Kudos
CherieMalone
Occasional Contributor

Hiya,

I had exactly the same issue and thought it might be useful to post the code to do this one thing here for everyone:

p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps('Map')[0] # Update the Map parameter to the Map's name
l = m.listLayers('Layer')[0] # Update the Layer parameter to the desired layer

# Isolate the symbology of the selected layer
sym = l.symbology

# Loop through each of the groups of features and update the labels
for grp in sym.renderer.groups:
for itm in grp.items:
# Combine the values of Field 1 and Field 2 with a hyphen
field1_value = itm.values[0][0] # First field (Field 1)
field2_value = itm.values[0][1] # Second field (Field 2)
# Set the label as the combined values with a hyphen
itm.label = f"{field1_value} - {field2_value}"

# Update the layer symbology to apply the new labels
l.symbology = sym

0 Kudos