I am trying to add a ROI in real-time with a button click. Once it is added, the ROI is blocking the line plot to scroll. I tried adding the line Plot widget as a parent to the ROI, that didn't work. Is there any way to make the ROI scroll outside of the view along with line plot? Also, how do I retain the historical data and ROIs, currently, the data is replaced by the new data.
Thanks.
import signal
import time
from math import sin
from threading import Thread
from time import sleep
import pyqtgraph as pg
from pglive.kwargs import Axis
from pglive.sources.data_connector import DataConnector
from pglive.sources.live_axis import LiveAxis
from pglive.sources.live_plot import LiveLinePlot
from pglive.sources.live_plot_widget import LivePlotWidget
"""
In this example Line plot is displayed.
"""
import random
import signal
import sys
from math import sin
from time import sleep
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QApplication,QPushButton
running = True
app = QApplication(sys.argv)
button = QPushButton('Add Rect')
def addRect(button):
print('Added')
roi= pg.ROI((time.time()-3,-1.5),(2,3),pen='g',movable=False)
roi.setZValue(10)
time_axis_plot_widget.addItem(roi)
button.clicked.connect(addRect)
def stop():
"""Stop current QApplication"""
global running
running = False
app.exit(0)
# Connect SIGINT with stop function
signal.signal(signal.SIGINT, lambda sig, frame: stop())
connectors = []
layout = pg.LayoutWidget()
# Define Time plot
left_axis = LiveAxis("left", axisPen="red", textPen="red")
bottom_axis = LiveAxis("bottom", axisPen="green", textPen="green", **{Axis.TICK_FORMAT: Axis.TIME})
time_axis_plot_widget = LivePlotWidget(title="Time Line Plot @ 100Hz",
axisItems={'bottom': bottom_axis, 'left': left_axis})
plot = LiveLinePlot()
time_axis_plot_widget.addItem(plot)
connectors.append(DataConnector(plot, max_points=600))
layout.addWidget(time_axis_plot_widget)
layout.addWidget(button)
layout.show()
def sin_wave_generator(*data_connectors):
"""Sinus wave generator"""
x = 0
while running:
x += 1
for data_connector in data_connectors:
data_connector.cb_append_data_point(sin(x * 0.01), time.time())
sleep(0.01)
Thread(target=sin_wave_generator, args=connectors).start()
signal.signal(signal.SIGINT, lambda sig, frame: stop())
app.exec()
stop()