<?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: Arc Toolbox Python script tool plot legend error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182099#M14007</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahhh.. tip as well.&amp;nbsp; I find there are sometimes 'issues' when you run user tools from catalog, rather than running them from an added toolbox in arctoolbox.&amp;nbsp; Can't nail down what it is exactly... I have been told it doesn't make a difference, but I have seen it happen..&amp;nbsp;&lt;/P&gt;&lt;P&gt;In short a reboot, makes you feel good when it works, so that is good&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;P&gt;You might want to close the thread to show an answer was found&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Nov 2017 00:08:33 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-11-21T00:08:33Z</dc:date>
    <item>
      <title>Arc Toolbox Python script tool plot legend error</title>
      <link>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182094#M14002</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a Python script with a optional function that when called creates terrain profile plots. When I run the script outside of ArcGIS it works fine, but when I package it up as a script tool in the Arc Toolbox to share with others it crashes with the following error message...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\pyplot.py", line 3552, in legend&lt;BR /&gt; ret = gca().legend(*args, **kwargs)&lt;BR /&gt; File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\axes\_axes.py", line 550, in legend&lt;BR /&gt; self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)&lt;BR /&gt; File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\legend.py", line 385, in __init__&lt;BR /&gt; self._init_legend_box(handles, labels, markerfirst)&lt;BR /&gt; File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\legend.py", line 654, in _init_legend_box&lt;BR /&gt; fontsize, handlebox))&lt;BR /&gt; File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\legend_handler.py", line 119, in legend_artist&lt;BR /&gt; fontsize, handlebox.get_transform())&lt;BR /&gt; File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\legend_handler.py", line 193, in create_artists&lt;BR /&gt; legline = Line2D(xdata, ydata)&lt;BR /&gt; File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\lines.py", line 286, in __init__&lt;BR /&gt; Artist.__init__(self)&lt;BR /&gt;TypeError: expected string or buffer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried many variations of the legend call in the script, but nothing has worked so far. I could get around this by not plotting a legend on the plots at all, but it is a useful reference and I would like to keep it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone else had a similar problem or a solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code in my function is something like this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fig = plt.figure(figsize=(18, 5))&lt;/P&gt;&lt;P&gt;axes = plt.gca()&lt;/P&gt;&lt;P&gt;axes.set_ylim(minY, maxY)&lt;/P&gt;&lt;P&gt;plt.plot(distances, elevations, label='Terrain Profile', linestyle='dashed')&lt;/P&gt;&lt;P&gt;plt.legend(loc="upper right", numpoints = 1)&lt;/P&gt;&lt;P&gt;fig.savefig(OutFilePath)&lt;/P&gt;&lt;P&gt;plt.close('all')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Nov 2017 22:30:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182094#M14002</guid>
      <dc:creator>JamesSturman</dc:creator>
      <dc:date>2017-11-20T22:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Arc Toolbox Python script tool plot legend error</title>
      <link>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182095#M14003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That error is internal to matplotlib and seems to have occurred when packaging.&amp;nbsp; That is going to be difficult to overcome since it may arise from a 'used name' conflict. &amp;nbsp;&lt;/P&gt;&lt;P&gt;As a check, you are importing matplotlib within your script aren't you?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Nov 2017 22:36:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182095#M14003</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-11-20T22:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Arc Toolbox Python script tool plot legend error</title>
      <link>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182096#M14004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan.&lt;/P&gt;&lt;P&gt;Yes I'm importing matplotlib right at the start of the script outside the functions like so...&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;import matplotlib.pyplot as plt&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;import numpy as np&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue is frustrating and&amp;nbsp;this morning when I first added the tool it appeared to work fine. I then had to make a few changes and it died. So it's not&amp;nbsp;always consistent.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Nov 2017 22:57:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182096#M14004</guid>
      <dc:creator>JamesSturman</dc:creator>
      <dc:date>2017-11-20T22:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Arc Toolbox Python script tool plot legend error</title>
      <link>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182097#M14005</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;nailing those down is hard... restart arcmap in between failures and ... what did you change! perhaps that is an issue that can be addressed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW&amp;nbsp; import arcpy last so that numpy and matplotlib (in theory) stake claim to namespace that may be duplicated further on during the arcpy import&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Nov 2017 23:20:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182097#M14005</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-11-20T23:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Arc Toolbox Python script tool plot legend error</title>
      <link>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182098#M14006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fantastic! Restarting ArcCatalog fixed it.&lt;/P&gt;&lt;P&gt;Great advice thanks again Dan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Nov 2017 00:01:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182098#M14006</guid>
      <dc:creator>JamesSturman</dc:creator>
      <dc:date>2017-11-21T00:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Arc Toolbox Python script tool plot legend error</title>
      <link>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182099#M14007</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahhh.. tip as well.&amp;nbsp; I find there are sometimes 'issues' when you run user tools from catalog, rather than running them from an added toolbox in arctoolbox.&amp;nbsp; Can't nail down what it is exactly... I have been told it doesn't make a difference, but I have seen it happen..&amp;nbsp;&lt;/P&gt;&lt;P&gt;In short a reboot, makes you feel good when it works, so that is good&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;P&gt;You might want to close the thread to show an answer was found&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Nov 2017 00:08:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arc-toolbox-python-script-tool-plot-legend-error/m-p/182099#M14007</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-11-21T00:08:33Z</dc:date>
    </item>
  </channel>
</rss>

