title: Matplotlib Runtime Error: main thread not in main loop
body: <p>I am not trying to thread any processes, but keep running into this error all over my Django site. I have seen a few other people ask this question but they are all attempting to use multiple threads. </p>
  
  <p>This is on Django 1.11, Python 3.6, Matplotlib 2.0.0. I also will note that this issue occurs on my mac, but not on my live Heroku server. </p>
  
  <p>I am using Pyplot to create some visualizations of models instances the users make, and get this about half the time I try to run it: </p>
  
  <p>Exception Type:     RuntimeError</p>
  
  <p>Exception Value:    main thread is not in main loop</p>
  
  <p>The last line of my code that runs is simply the plt.figure() call</p>
  
  <p>Trace:</p>
  
  <pre><code>File "/Users/Mark/Desktop/Professional/FSC/water/WATER/hydrograph/views.py" in processData
    397.         hydroFigure = plt.figure()
  
  File "/Users/Mark/Desktop/Professional/FSC/water/WATER/ENV/lib/python3.6/site-    packages/matplotlib/pyplot.py" in figure
    535.                                         **kwargs)
  
  File "/Users/Mark/Desktop/Professional/FSC/water/WATER/ENV/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py" in new_figure_manager
    81.     return new_figure_manager_given_figure(num, figure)
  
  File "/Users/Mark/Desktop/Professional/FSC/water/WATER/ENV/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py" in new_figure_manager_given_figure
    98.         icon_img = Tk.PhotoImage(file=icon_fname)
  
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py" in __init__
    3539.         Image.__init__(self, 'photo', name, cnf, master, **kw)
  
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py" in __init__
    3495.         self.tk.call(('image', 'create', imgtype, name,) + options)
  
  Exception Type: RuntimeError at /hydrograph/
  Exception Value: main thread is not in main loop
  </code></pre>
  
  <p>Any ideas on what I can do?</p>