1

Using python and matplotlib, I would like to compute some data, then plot it in a window, then compute some more, then update the plot in the same window. Each computation can be 1 second to 1 minute. Is there a way to achieve this without pain, across platforms (including osx)?

  1. I know that 'interactive mode' is supposed to handle this. But this requires changing the backend of matplotlib and installing a special "framework build" of python on osx. Completely unacceptable. I really don't want to require users to do that.

  2. Animations in matplotlib are time-driven, not 'event driven'. Impedance mismatch: doable, but not great - I would have to put the 'computation loop' into the 'animation loop'. I'd rather not.

  3. Multiprocessing to the rescue? i.e. compute, throw results to separate process over queue, render in the other process? I can't, for the life of me, get matplotlib to render anything in another process. Maybe this is another 'backend/build' issue.

...there's gotta be a way, this seems so basic...

Colin
  • 3,670
  • 1
  • 25
  • 36
  • 1
    Are you looking for something like [this](https://stackoverflow.com/questions/4098131/how-to-update-a-plot-in-matplotlib)? – abc Sep 06 '20 at 18:19
  • No, because: `plt.ion()`, or tkinter: not ideal. – Colin Sep 06 '20 at 18:22
  • Have you considered `pyqt5` and creating a plot window in a GUI that can be updated? See https://www.learnpyqt.com/courses/graphics-plotting/plotting-matplotlib/ – GeneralCode Sep 06 '20 at 18:45

1 Answers1

0

No perfect answer. I went with inversion of control through a FuncAnimation with a very short interval that does

animation.event_source.stop()
perform_some_computation()
animation.event_source.start()

to pause and resume the animation, and perform computation for each animation step. Not too tedious...

Colin
  • 3,670
  • 1
  • 25
  • 36