The problem is that you are using an interactive backend which is trying to create figure windows for you, which are failing because you have disconnected the x-server that was available when you started the simulations.
Change your imports to
import matplotlib
matplotlib.use('pdf')
import matplotlib.pyplot as plt