AnsweredAssumed Answered

matplotlib show() prevents script from completing

Question asked by timothy_hales-esristaff Employee on Oct 28, 2016
Latest reply on Nov 29, 2016 by timothy_hales-esristaff

I have a script tool that creates a graph using matplotlib. I use plt.show() to display the graph, but the script does not continue until I close the window. Thanks to Dan Patterson and X-Y graphing demo using pyplot (matplotlib)...an introduction I found plt.close(), but is there a way to allow the script to continue while keeping the plot window open?

 

import matplotlib.pyplot as plt

#Processing Step

#Create Graph
tName = "tableLocation.txt"
outputFile = "outputFigure.png"

x = []
y = []

with open(tName) as f:
    next(f)
    for line in f:
        parts = line.split(",")
        x.append(parts[2])
        y.append(parts[3])

fig = plt.figure()
plt.plot(x, y)
plt.xlabel('Distance')
plt.ylabel('Elevation')
fig.suptitle("Graph Title")
plt.show()
fig.savefig(outputFile)

#Next Processing Step

Outcomes