<?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 Re: Need help with legend order after python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1592006#M73863</link>
    <description>&lt;P&gt;Maybe look into matplotlib?&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 21:42:02 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2025-03-04T21:42:02Z</dc:date>
    <item>
      <title>Need help with legend order after python script</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1591590#M73859</link>
      <description>&lt;P&gt;Hello, I'm having trouble with the ordering of my legend.&lt;/P&gt;&lt;P&gt;When I export a map using Python, the layer order automatically changes to alphabetical.&lt;/P&gt;&lt;P&gt;For example, instead of the correct order (1–15), my legend appears as:&lt;BR /&gt;&lt;STRONG&gt;1-10-11-12-13-14-15-2-3-4-5-6-7-8-9&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I'm running the Python script in a PythonCaller within FME. When exporting manually in ArcGIS Pro, this issue does not occur—it only happens when exporting through my FME workspace and Python script.&amp;nbsp;The layer order setting is turned off, but even when I turn it on, it doesn't make a difference. In the python script itself, there is no piece of code regarding this sorting or regarding the legend.&lt;/P&gt;&lt;P&gt;Is there a way to prevent this automatic alphabetical sorting? Thank you in regard!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 09:50:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1591590#M73859</guid>
      <dc:creator>HackRentmeesters</dc:creator>
      <dc:date>2025-03-04T09:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with legend order after python script</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1591608#M73860</link>
      <description>&lt;P&gt;That sounds like an FME issue.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are coding everything, you can produce a "natural sort" of the text representation of numbers.&amp;nbsp; It is a known issue when sorting numbers that are now text.&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/4836710/is-there-a-built-in-function-for-string-natural-sort" target="_blank"&gt;python - Is there a built in function for string natural sort? - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;P&gt;there are a number of options additions that you could make to the sorting.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 12:17:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1591608#M73860</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-03-04T12:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with legend order after python script</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1591727#M73862</link>
      <description>&lt;P&gt;I usually just use a dead simple regex lambda and pass that as a sort key:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import re
natsort = lambda s: [int(t) if t.isdigit() else t.lower() for t in re.split(r'(\d+)', s)]

&amp;gt;&amp;gt;&amp;gt; vals = ['1', '2', '3', '4', '10', '20', '30', '40']
&amp;gt;&amp;gt;&amp;gt; vals.sort()
&amp;gt;&amp;gt;&amp;gt; vals
['1', '10', '2', '20', '3', '30', '4', '40']

&amp;gt;&amp;gt;&amp;gt; vals.sort(key=natsort)
&amp;gt;&amp;gt;&amp;gt; vals
['1', '2', '3', '4', '10', '20', '30', '40']&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 04 Mar 2025 16:37:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1591727#M73862</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-03-04T16:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with legend order after python script</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1592006#M73863</link>
      <description>&lt;P&gt;Maybe look into matplotlib?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 21:42:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-legend-order-after-python-script/m-p/1592006#M73863</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-03-04T21:42:02Z</dc:date>
    </item>
  </channel>
</rss>

