At the end of the last function I call in one of my programs, I have the following code to plot a simple color plot.

plt.figure()
plt.pcolormesh(X,Y,Z)
plt.colorbar()
plt.show()

Afterwords I return to main and my program is complete. The plot displays as expected, however when I go to close it using the x button in the corner (on ubuntu), my program doesn’t end. It just hangs there with a process running. How can I correct this?

your matplotlib might be running in non-interactive mode for some reason.
I am not sure how to prevent that in your local configuration but if you add either this:

plt.ion()

or this:

matplotlib.interactive(True)

somewhere at the beginning of your script, it should change the behaviour of your plots.

For interactive mode, You need this at the head of file:

import matplotlib
matplotlib.use("TkAgg")