The problem is that the Python process ends after the last iteration of the loop, forand therefore also terminates with widgets. You can use the switch -ito enter an interactive Python interpreter after executing a script that saves all the objects that were created during the execution of the script:
python -i /path/to/script.py
, , pyqtgraph, , "" (, show matplotlib.pyplot ), pyqtgraph.