Closed rbregand closed 1 year ago
Oh OK, this is normal...
You have run this code in a python script, shell, or ipython, but without running the Qt event loop. Pyaims makes use of matplotlib, and of Qt, so at some point it sets the matplotlib backend to use Qt. Thus plt.plot()
needs a QApplication
instance and a running event loop. I'm not sure when this backend is forced, I thought it was only when importing the Qt wapper (soma.qt_gui.qt_backend
) and I don't see when it is used by just importing aims and using aims.read(), but that's apparently what happens.
To solve it:
ipython --gui=qt
, or inside a running ipython, type %gui qt
otherwise you need to use QApplication
:
from soma import aims
import matplotlib.pyplot as plt
from soma.qt_gui.qt_backend import Qt
img = aims.read("/home/remy.bregand/Bureau/test_dcm2niix/GREim/DV/dcm/PV.nii")
app = Qt.QApplication([])
plt.plot([1, 2])
plt.show()
app.exec()
It it the same for any Qt graphical interface, thus for matplotlib when using the Qt backend. In your second example using nibabel, the matplotlib backend is not set to Qt, and it is certainly using another one (I don't know which), as matplotlib is able to render using different graphical toolkits (which are completely exclusive: you cannot run in the same program Qt and Gtk widgets, for instance).
Ok, I understand. Thanks for the explanation, I will keep this solution in mind the next time this error occurs. It's alright for me, I will close the issue
Hi,
I noticed a weird behavior when aims and matplotlib are used in the same code. You will found the code to replicate the issue below :
output error : QWidget: Cannot create a QWidget without QApplication
The problem doesn't not occur when I'm using nibabel instead of aims to read the nifti file.
Environment :
Have you already notice it ? This issue is not critical, I just want you to be aware of it.
Thanks for your time