title: Watchdog and matplotlib: Processing an image and displaying results when a new file comes in directory
body: <p>I am trying to create a simple app in which </p>
  
  <ol>
  <li><p>an image is pushed in a directory (by an outside process)</p></li>
  <li><p>Python watchdog triggers and the image is processed by a function and results are displayed in a window </p></li>
  </ol>
  
  <p>The job is continuously running and the processing function is triggered as the image comes into the directory. The plot window for results should just be updated with new results instead of window closing and then re-plotting. </p>
  
  <p>The code below does not display the results. The plot window remains blank and then crashes. If something other than matplotlib can do this job easily then that would be fine as well. </p>
  
  <pre><code># plt is matplotlib.pyplot
  
  def process_and_plot(test_file):
      y, x = getresults(test_file) # function which returns results on image file
  
      y_pos = range(len(y))
      plt.figure(num=1,figsize=(20,10))
      plt.bar(y_pos, y, align='center')
      plt.xticks(y_pos, x)
      plt.show()
  
  # to trigger the proess_and_plt function when a new file comes in directory 
  
  class ExampleHandler(FileSystemEventHandler):
      def on_created(self, event): 
          print event.src_path
          process_and_plot(event.src_path)
  
  event_handler = ExampleHandler() 
  observer.schedule(event_handler, path='path/to/directory')
  observer.start()
  try:
      while True:
          time.sleep(1)
  except KeyboardInterrupt:
      observer.stop()
  
  observer.join()
  
  </code></pre>