LegendItem

Resumen

LegendItem provides access to legend item level information in a LegendElement.

Debate

The items property on the LegendElement class returns a list of LegendItem objects. For each legend item, you can change properties such as arrangement, patchHieght, and its visible status. The typical workflow is to iterate through the list of elements, determine the item of interest by its name property, then make the appropriate changes.

Propiedades

PropiedadExplicaciónTipo de datos
arrangement
(Lectura y escritura)

A string that determines the legend item arrangement. The following is a valid list of values:

  • PatchLabelDescriptionPatch, label, description
  • PatchDescriptionLabelPatch, description, label
  • LabelPatchDescriptionLabel, patch, description
  • LabelDescriptionPatchLabel, description, patch
  • DescriptionPatchLabelDescription, patch, label
  • DescriptionLabelPatchDescription, label, patch
String
column
(Lectura y escritura)

The column position for a legend item. The column property only applies to legends using the ManualColumns fitting strategy.

Long
name
(Sólo lectura)

Returns the legend item name. The legend item name is set by modifying the layer name.

String
patchHeight
(Lectura y escritura)

The height of a legend item patch. Units are in points.

Double
patchWidth
(Lectura y escritura)

The width of a legend item patch. Units are in points.

Double
showFeatureCount
(Lectura y escritura)

A Boolean that controls whether the feature count is placed next to the legend item text. The value displayed is dependent on the showVisibleFeatures setting.

Boolean
showVisibleFeatures
(Lectura y escritura)

A Boolean that controls whether the legend item displays all values or only those values that appear in the visible extent.

Boolean
type
(Sólo lectura)

Returns a value of LEGEND_ITEM.

String
visible
(Lectura y escritura)

Returns True if the legend item is visible in the legend.

Boolean

Muestra de código

LegendItem example

The following script iterates through all legend items in a legend. Its sets the patchHieght and patchWidth for all legend items, then sets showVisibleFeatures for a specific legend item.

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]
leg = lyt.listElements('LEGEND_ELEMENT')[0]

#Change the patch size for all legend items
#only display features in the visible map frame extent
for itm in leg.items:
  itm.patchHeight = 15
  itm.patchWidth = 30
  if itm.name == 'Geological Types':
    itm.showVisibleFeatures = True