LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview Python Node: Multiple Concurrent Figures in matplotlib possible?

Solved!
Go to solution

I'm using the Python node with Python 3.6, 32 bit, and Matplotlib 3.3.0.  I'm trying to construct two figures at once, and then save both to .JPG.  I follow the NI provided example of creating/saving a figure which includes the line matplotlib.use('Agg') to write to the backend.  However my script also contains commands matplotlib.pyplot.fig(n) to write to a figure #n.  The code works fine outside of Labview, but as soon as I call it from the Python node it fails, when the fig method is called.  Is there a way to construct two figures at the same time?  Below is the actual error message. 

 

I'd have to write code from scratch if someone needs code to replicate the error which will take quite a while, so is not my first choice, since I hope that what I want to do is pretty straightforward to someone familiar with matplotlib.

 

I can of course build up one figure sequentially, then start over and build up another, but it will either make my code more complicated or lead to me processing all my data twice.  I am already using subplots.  Subplots don't solve my issue.

 

Thanks, Jon

--- --- ---

Error 1671 occurred at Python Node in motors_cld_power_ircamera2.vi

 

Possible reason(s):

LabVIEW: (Hex 0x687) There was an error in executing the specified function.


Module Path: C:\Users\jroth\Documents\LabView32bit\InstrumentControls\LabViewPython\saveLIVv3.py
Function Name: singletestandanalyze
Python returned the following error: <class 'AttributeError'>
module 'sys' has no attribute 'argv'


Call Stack information:
File "C:\Users\jroth\Documents\LabView32bit\InstrumentControls\LabViewPython\saveLIVv3.py", line 16, in singletestandanalyze
return analyzedata(data_dir)
File "C:\Users\jroth\Documents\LabView32bit\InstrumentControls\LabViewPython\saveLIVv3.py", line 111, in analyzedata
testdict[testkey] = analyzecase(testval)
File "C:\Users\jroth\Documents\LabView32bit\InstrumentControls\LabViewPython\saveLIVv3.py", line 223, in analyzecase
plt.figure(1)
File "C:\Users\jroth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\pyplot.py", line 676, in figure
**kwargs)
File "C:\Users\jroth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\pyplot.py", line 298, in new_figure_manager
return _backend_mod.new_figure_manager(*args, **kwargs)
File "C:\Users\jroth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backend_bases.py", line 3490, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "C:\Users\jroth\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\_backend_tk.py", line 859, in new_figure_manager_given_figure
window = tk.Tk(className="matplotlib")
File "C:\Users\jroth\AppData\Local\Programs\Python\Python36-32\Lib\tkinter\__init__.py", line 2018, in __init__
baseName = os.path.basename(sys.argv[0])

AttributeError: module 'sys' has no attribute 'argv'

0 Kudos
Message 1 of 7
(1,975 Views)

You may have figured this out already, but my bet is that the package that Matplolib is calling to make the multiplot.pyplot.fig(n) work isn't installed in the place that python expects it to be when called from LabVIEW.  

 

You could do it all in LabVIEW using the Advanced Plotting Toolkit which is a LabVIEW interface to Matplotlib.  You can look at an example of that here - https://forums.ni.com/t5/Advanced-Plotting-Toolkit/Speed-Up-Execution-and-Parallelization/gpm-p/3779...

 

Craig

Message 2 of 7
(1,869 Views)
Solution
Accepted by topic author jonroth

Thanks.

For some reason I can't follow your link to see the solution you're suggesting?

 

I did find a workable solution in the meantime.  Before calling the figure() method, the following command must be executed:

 

matplotlib.pyplot.ioff()

 

The meaning of this command is "turn interactive mode off".  I think it stops trying to open a figure window in Python, which seems to not be possible when it's called from Labview.

0 Kudos
Message 3 of 7
(1,864 Views)

Glad you found a solution! 

 

I fixed the link in the reply above.

 

Craig

0 Kudos
Message 4 of 7
(1,857 Views)

Thanks!

0 Kudos
Message 5 of 7
(1,850 Views)

Hi Jonroth,

 

I'm facing the same issue that you faced. But matplotlib.pyplot.ioff() is not working for me. The error was same as before using the "matplotlib.pyplot.ioff()"

 

I'm using LabVIEW 2018 64 bit & Python 3.6.5 64 bit. Do you aware of any other solution or reason for this?

 

Thanks in advance

0 Kudos
Message 6 of 7
(1,578 Views)

Hi Suhailahamed144,

 

I didn't investigate this any more once I found a solution that worked for me.  Maybe someone in the support community can reply and help.

 

Jon

0 Kudos
Message 7 of 7
(1,562 Views)