<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Feature layer legend label format with arcpy in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1572806#M91661</link>
    <description>&lt;P&gt;How can I round to 2 decimal places the feature class legend label in arcgis pro with python code, if it is divided into 5 classes using natural break method? The value is rounded up with my code, but still 6 decimal places are displayed. How to do it from code, because it would be part of a pdf printer process and it would be very important that the symbol explanation is easy to read. I can only do this by manual adjustment (Advanced symbolgy options/Rounding).&amp;nbsp;&lt;/P&gt;&lt;P&gt;original label:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.234567 - 0.41277&lt;/P&gt;&lt;P&gt;rounded by script: 0.230000 - 0.410000&lt;/P&gt;&lt;P&gt;I would like this:&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.23 - 0.41&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;p = arcpy.mp.ArcGISProject('CURRENT')&lt;BR /&gt;m = p.listMaps('MAP')[0]&lt;BR /&gt;l = m.listLayers("NDVI_mean")[0]&lt;BR /&gt;sym = l.symbology&lt;/P&gt;&lt;P&gt;if sym.renderer.type == "GraduatedColorsRenderer":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if sym.renderer.classificationMethod == "NaturalBreaks":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; breaks = sym.renderer.classBreaks&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for tor in breaks:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rounded_break_values = round(float(tor.upperBound), 2)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tor.upperBound = rounded_break_values&lt;BR /&gt;l.symbology = sym&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2025 16:03:00 GMT</pubDate>
    <dc:creator>ErzsikeTerezsi</dc:creator>
    <dc:date>2025-01-06T16:03:00Z</dc:date>
    <item>
      <title>Feature layer legend label format with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1572806#M91661</link>
      <description>&lt;P&gt;How can I round to 2 decimal places the feature class legend label in arcgis pro with python code, if it is divided into 5 classes using natural break method? The value is rounded up with my code, but still 6 decimal places are displayed. How to do it from code, because it would be part of a pdf printer process and it would be very important that the symbol explanation is easy to read. I can only do this by manual adjustment (Advanced symbolgy options/Rounding).&amp;nbsp;&lt;/P&gt;&lt;P&gt;original label:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.234567 - 0.41277&lt;/P&gt;&lt;P&gt;rounded by script: 0.230000 - 0.410000&lt;/P&gt;&lt;P&gt;I would like this:&amp;nbsp; &amp;nbsp; &amp;nbsp; 0.23 - 0.41&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;p = arcpy.mp.ArcGISProject('CURRENT')&lt;BR /&gt;m = p.listMaps('MAP')[0]&lt;BR /&gt;l = m.listLayers("NDVI_mean")[0]&lt;BR /&gt;sym = l.symbology&lt;/P&gt;&lt;P&gt;if sym.renderer.type == "GraduatedColorsRenderer":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if sym.renderer.classificationMethod == "NaturalBreaks":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; breaks = sym.renderer.classBreaks&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for tor in breaks:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rounded_break_values = round(float(tor.upperBound), 2)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tor.upperBound = rounded_break_values&lt;BR /&gt;l.symbology = sym&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 16:03:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1572806#M91661</guid>
      <dc:creator>ErzsikeTerezsi</dc:creator>
      <dc:date>2025-01-06T16:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Feature layer legend label format with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1572811#M91662</link>
      <description>&lt;LI-CODE lang="python"&gt;a = 1.2345678
float(f"{round(a,2):.2f}")
1.23&lt;/LI-CODE&gt;&lt;P&gt;might work unless the upperBound etc is handled after the number formatting&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 16:26:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1572811#M91662</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-01-06T16:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Feature layer legend label format with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1573076#M91678</link>
      <description>&lt;P&gt;I personally have found trying to change the labels in symbols always a bit flaky through direct manipulation of arcpy classes, but may be that's just me...&lt;/P&gt;&lt;P&gt;Anyway an alternative method is to access the CIM object module for fine tuning layer properties, this includes symbology.&amp;nbsp; As you say in your question you can easily change the decimal places through &lt;SPAN&gt;Advanced symbology options in&amp;nbsp;&lt;/SPAN&gt;the UI, so lets replicate that!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# Get handle on layer in first map
p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps('MAP')[0]
l = m.listLayers("fc_AreasMerged")[0]
sym = l.symbology

# Change rounding value using CIM
lcim = l.getDefinition('V2')
lcim.renderer.numberFormat.roundingValue = 2
l.setDefinition(lcim)

# Update/refresh renderer
sym = l.symbology
sym.updateRenderer ('GraduatedColorsRenderer')
l.symbology = sym&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to get into manipulating CIM, best bit advice I can give is get hold of the &lt;A href="https://github.com/Esri/arcgis-pro-sdk-cim-viewer/issues/10" target="_self"&gt;CIM viewer AddIn&lt;/A&gt;, this allows you to see the CIM for a layer selected in the Contents Pane. I couldn't live without it!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 13:43:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1573076#M91678</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2025-01-07T13:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Feature layer legend label format with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1573462#M91710</link>
      <description>&lt;P&gt;Thank you! It is work fine.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 08:55:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/feature-layer-legend-label-format-with-arcpy/m-p/1573462#M91710</guid>
      <dc:creator>ErzsikeTerezsi</dc:creator>
      <dc:date>2025-01-08T08:55:25Z</dc:date>
    </item>
  </channel>
</rss>

