# Slight modification of the programs discussed in # http://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue # by http://stackoverflow.com/users/17160/nosklo from matplotlib import plot, draw, show, ion from multiprocessing import Process def TheProblem() : plot([1,2,3]) show() print 'This will not be printed until the plot is closed.' def SolutionUsingDraw() : plot([1,2,3]) draw() print 'continue computation' # at the end call show to ensure window won't close. show() def SolutionUsingInteractiveMode() : ion() # enables interactive mode plot([1,2,3]) # result shows immediatelly (implicit draw()) print 'continue computation' # at the end call show to ensure window won't close. show() def SolutionUsingMultiprocessingModule() : def plot_graph(*args): for data in args: plot(data) show() p = Process(target=plot_graph, args=([1, 2, 3],)) p.start() print 'computation continues...' print 'Now lets wait for the graph be closed to continue...:' p.join() # This has the overhead of launching a new process, and is sometimes harder to debug on complex scenarios, # so I'd prefer the other solution (using matplotlib's nonblocking API calls) if __name__ == '__main__': TheProblem() SolutionUsingDraw() SolutionUsingInteractiveMode() SolutionUsingMultiprocessingModule()