2

I have problems using the matplotlib for python with ArcGIS 10.1

If I run the code below as a script tool in ArcMap. No pdf is generated and when I close ArcMap this error is shown.

enter image description here

If I run the code from IDLE a similar error is shown for C:\Python\ArcGIS10.1\pythonw.exe but the pdf is generated correct.

If I run the code in a cmd prompt no error code is shown and the pdf is generated correct.

Does anybody know how to make the script work as a script tool in ArcMap?

from matplotlib import pyplot

fig = pyplot.figure(figsize=(8.27,11.69))

axis1 = fig.add_subplot(311)
axis1.plot(range(10))

fig.savefig('multipleplots.pdf')
  • Are you running pyplot in interactive mode (does the plot show up automatically when you create the figure)? Interactive mode is incompatible with both ArcGIS and IDLE. – Evil Genius Apr 24 '14 at 11:37
  • No the plot does not show up automatically. I also tried adding matplotlib.pyplot.ioff() to the code but the error still pops up. But maybe there is another way I need to turn off interactive mode? – Mathiaskopo Apr 24 '14 at 11:46
  • That should have done it...does it work with a different format, like png? – Evil Genius Apr 24 '14 at 11:48
  • No change output to .png does not create any output within ArcMap – Mathiaskopo Apr 24 '14 at 11:52
1

I'm super late to the party, but I had the same problem today and your post came up during my google search. So I guess posting a solution could be useful to someone in the future.

Anyways, I avoided the Microsoft Visual C++ crash when closing ArcMap by closing the matplotlib figure after saving it.

pyplot.close(fig)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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