I would like to label points in ArcMap, and the labels contain chemical formulas. These chemical formulas have both subscripts and superscripts (see snip below)
I am unable to use labels that both retain sub/superscript formatting, and have a mask (like the point names in the image below). If I add a text box to manually (copy-paste) label all points with text formatting, I can not add a mask. (This is why they appear as such)
Attribute tables don't retain sub/superscript formatting, and as such display as plain text if I label directly from the attribute table.
Is there a way to have the formatting of sub/superscripts in the chemical formulas show in the labels, and still be able to use a mask? I have a large number of points so I would like to use the attribute table. However the only way I can think of to accomplish this is by exploding every part of each chemical formula into its own field (seeing as I have hundreds of points this doesn't seem realistic)
OKAY. Lukes code works great but I cannot get it to work with my code. This is my code without sub/super formatting:
def FindLabel ( [Name], [Spring_Exc], [Fall_Exc] ):
return [Name] + "" + [Spring_Exc] + " " + "" + "\r\n"+[Fall_Exc] + " "
& This is what it looks like:
I need it to retain the sub/super formatting; This is what Luke came up with:
def FindLabel ([Spring_Exc]):
formats = {
'SiO2': 'SiO2',
'CO32-': 'CO32-',
'HCO2-': 'HCO2- 'HCO3': 'HCO3'
}
formulas = [Spring_Exc].strip('()').split(',')
labels = [formats.get(f, f) for f in formulas]
return '({})'.format(','.join(labels))
& this is what Lukes code looks like, it accomplishes my formatting issue.
I am looking to have [Spring_Exc] & [Fall_Exc] to be labeled with sub/super formatting, as subscripts of the point name. It should look like screenshot #3 but retain formatting.
My most recent thought is that I would have to approach it like this: (However I am not sure if this thinking is correct, as there are errors)
def FindLabel ( [Name], [Spring_Exc], [Fall_Exc] ):
formats = {
'SiO2': 'SiO2',
'CO32-': 'CO32-',
'HCO2-': 'HCO2- 'HCO3': 'HCO3'
}
formulas = [Spring_Exc].strip('()').split(',')
formula = [Fall_Exc].strip('()').split(',')
labels = [formats.get(f, f) for f in formulas]
labels = [formats.get(f, f) for f in formula]
return '({[Name] + "" + [Spring_Exc] + " " + "" + "\r\n"+[Fall_Exc] + " "})'.format(','.join(labels))
This is how Lukes code appears in my expression popup, I have advanced checked and have selected the python parser:
I'm not sure how to fix my issue of combining these two codes into one.
No comments:
Post a Comment