OE-FET / keithley2600

Python driver for Keithley 2600 series instruments.
https://keithley2600.readthedocs.io
MIT License
41 stars 17 forks source link

matplotlib backend definition for live plotting #15

Closed ozumana closed 4 years ago

ozumana commented 4 years ago

Hi @SamSchott

How can I specify Qt5Agg as backend for Matplotlib (as required for live plotting)?

I am running one of your usage examples, which drives flawlessly my 2636B... the only problem is that plotting is not updating... and runs with the warning message below.

C:\Anaconda3\envs\MSS\lib\site-packages\keithley2600\result_table.py:766: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.

Thanx

samschott commented 4 years ago

In an IPython console, this is as simple as running %gui qt. You can also programatically choose your backend with matplotlib.use('Qt5Agg') before importing any plotting modules.

More information is available in the Matplotlib docs.

Hope this helps, Sam

ozumana commented 4 years ago

Thank you for the simple fix... however, I note that a plt.pause command was necessary in my code to ensure that the plot live refresh was visible.

samschott commented 4 years ago

Yes, you'll need to do that if your are adding data in the main thread. The GUI needs some time to do the actual plotting and plt.pause gives it that time.

I have added notes on this to the documentation.

SirNate0 commented 2 months ago

On Windows I found I had to manually switch to that back end (on Linux I guess it was the default). An oddity I encountered in this was that I had to do any one of the following to get it to work:

  1. Call matplotlib.use('Qt5Agg') before I imported matplotlib.pyplot. If I did that after the pyplot import, then there would be no warning message, but the plot would not update (even when saving the figure - just an empty graph saved).
  2. Manually call the update() function on the ResultTablePlot
  3. Use plt.switch_backend('Qt5Agg') instead of matplotlib.use (obviously after importing pyplot as plt).