<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi Jandyman,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 6, 2020 at 7:41 PM jandyman <<a href="mailto:andy@voelkel.us" target="_blank">andy@voelkel.us</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I've spent several hours trying to figure out how to get interactive plots<br>
to work on MacOS Catalina (plots which don't block program execution). I got<br>
fairly excited when I found instructions in the Matplotlib docs for using<br>
python as a framework and then using the macosx backend, but it doesn't seem<br>
to help. </blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I also find the 'macosx' backend to be challenging for interactive work.   It seems you have to keep hitting return in the main python REPL  for the 'macosx' event loop to process.  The other backends do not need this. In particular, the 'qt5agg' and 'tkagg' backends will do what (I think) you are looking for:  `pyplot.ion()` will make `pyplot.plot()` draw to the screen immediately with a responsive plot window and not block the REPL.   The 'wxagg' backend should be able to do this, but it appears that `pyplot.ion()` does not actually work as it does for 'qt5agg' and 'tkagg' -  I don't know why that it is.</div></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">You might find `wxmplot` (<a href="https://newville.github.io/wxmplot/" style="font-family:Arial,Helvetica,sans-serif" target="_blank">https://newville.github.io/wxmplot/</a> -- I am the author of this) useful for interactive work from the Python REPL (or from IPython for that matter).  With this, you would do something like:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">    >>> import numpy as np<br>
    >>> from wxmplot.interactive import plot<br>    >>> x = np.linspace(0, 20, 100)  <br>    >>> pd = plot(x, np.sin(x))</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">This will immediately bring up a separate plot window and returning control to the REPL.  The window is highly interactive: you can zoom in, save images, and alter nearly every aspect of the plot (colors, themes, linewidths, styles, markers, text labels, margins, legend display, log scales, etc) from a configuration panel.  You can also easily plot to multiple window frames, say with</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">    >>> pd2 = plot(x, np.cos(x), win=2)<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Of course, not every aspect of matplotlib is exposed in `wxmplot`. The return value from `plot` has a `panel.axes` attribute that is the `matplotlib.axes`, which can be used for more complicated plot components.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">There is also a `wxmplot.interactive.imshow` for showing false-color images from 2-d arrays that also has many interactive options (color tables, contrast, smoothing, etc).  `wxmplot` can be installed with `pip install wxmplot`.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><div class="gmail_default">There is a nasty problem with Anaconda Python on MacOS that `python` is not a framework build and so the wxPython module cannot draw to the screen, and trying to do so exits python.  Instead, one needs to use `pythonw` (from the `python.app` conda package) to use wxPython with Anaconda Python on MacOS.   I do not know why this is.  This is merely irritating for running scripts or applications, but is particularly problematic when using IDEs such as Spyder or Idle, as they embed a Python interpreter that has been launched with `python`, not `pythonw`.   For me, VSCode works fine as it uses python from Python.org which does not have this problem.</div><div class="gmail_default"><span style="font-family:Arial,Helvetica,sans-serif"> </span><br></div><div class="gmail_default"><span style="font-family:Arial,Helvetica,sans-serif">Hope that helps,</span></div><div class="gmail_default"><span style="font-family:Arial,Helvetica,sans-serif"><br></span></div></div></div><div dir="ltr">--Matt Newville<br></div>
</div>