i am playing around with a Plotwidget and i cant figure out how i can find the min-max positions from my list when zooming in and out.
Lets say i have a list which has 1000 values. When im scrolling/zooming i can only figure out the viewbox range and not the positions i am in my list.
Example:
- On init i am at x[0], x[1000]
- Scrolling once im at x[?], x[?]
Is it possible to find out the min-max index (if i am not directly on an index , whats the closest one)? I also would like to know, if it is possible to change the zooming factor when scrolling and can i set the viewbox padding to 0? I only figured out that u can change this with setXRange(..., padding=0)
import sys
from random import randint
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
from PyQt5.QtCore import Qt
import pyqtgraph as pg
class Win(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.graph = pg.PlotWidget()
self.setCentralWidget(self.graph)
self.graph.sigRangeChanged.connect(self.viewboxChanged)
x = list()
y = list()
pos = 0
for i in range(1000):
r = randint(0,5)
y.append(r)
x.append(pos)
pos +=r
self.graph.plot(x, y)
def viewboxChanged(self, view, range):
print(range)
pass
if __name__ == "__main__":
app = QApplication(sys.argv)
win = Win()
win.show()
sys.exit( app.exec_() )