I'm developing a Python script to created several map document (.mxd) files from .shp file and .xlsx file automatically. After setting symbology of layer and changing labels, I want to hide heading of legend by working on "show heading" option on "Legend Item Properties", but unfortunately I cannot found this property. Here is part of my code:

def CreateMXD(srcMXDDir, srcMXDName, srcSHPDir, srcLyrDir, srcStyleName, srcXlsxWB):
    srcLayer = arcpy.mapping.Layer(srcLyrDir)
    mxd = arcpy.mapping.MapDocument(srcMXDDir + "//" + srcMXDName + '.mxd')
    mxdDF0 = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    # mxdDF1 = arcpy.mapping.ListDataFrames(mxd2, "Layers")[1]
    mxdLayer = arcpy.mapping.Layer(srcSHPDir)
    arcpy.mapping.AddLayer(mxdDF0, mxdLayer, "TOP")
    addLayer = arcpy.mapping.ListLayers(mxd, "", mxdDF0)[0]

    fields = arcpy.ListFields(srcSHPDir)
    for field in fields:
        fieldType = field.type
        fieldName = field.name
        if fieldType in ["Double", "Integer", "Long"] and fieldName.startswith('edu'):
            arcpy.mapping.UpdateLayer(mxdDF0, addLayer, srcLayer, True)
            # print(addLayer.symbologyType)
            if addLayer.symbologyType == 'GRADUATED_COLORS':
                addLayer.symbology.valueField = fieldName
                labels = addLayer.symbology.classBreakLabels
                    addLayer.symbology.classBreakLabels = ["{} - {}".format(*r)
                                                                         for r in [
                                                                             [round(float(f), 2) for f in lab.split(" - ")]
                                                                             for lab in labels
                    print('Error in Symbology | %s' % fieldName)

This link has described this functionality in ArcMap but I want to do this change using ArcPy scripting. Below you can see the screen of my MXD file and mentioned option in ArcMap:

Arcmap show heading option


2 Answers 2


Using ArcGIS 10.4 (not Pro version), I did this by defining new style and then updating legend. So by double-click on labels in legend an going to Legend Properties > Style... > Properties... I could turn Show Heading option off. After applying changes, I named it df0_legend_style and saved it as a new style. Below image shows how we can create new style in ArcMap:

enter image description here

When I created the style, I added these codes to my script:

newStyle = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", df0_legend_style)[0]
mxd_legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
mxd_legend.title = ""
mxd_legend.updateItem(addLayer, newStyle)

This code update Legend Item by newly created style.


As commented by @Vince:

ArcPy does not support all ArcObjects functionality, especially with regard to mapping and symbology.

In ArcGIS Pro there is an ItemGroup class and:

The ItemGroup class allows you to change a heading value for a group and more importantly provides access to the individual items in each group.

However, the ItemGroup class appears to only be available for a UniqueValuesRenderer.

Since you are using ArcMap and a GraduatedColorsRenderer, the above will not provide a solution but it may provide some ideas about where to look for the functionality you seek within ArcGIS Desktop when you are using ArcPy with ArcGIS Pro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.