سؤال

I have 4 PlotWidgets (using pyqtgraph as pg) created as:

for i in range(4):
    myPlot[i] = pg.PlotWidget(myWindow);

In each PlotWidget, I want to divide the x-axis to several regions with equal width (RegionWidth). Therfore, I have M = x-axis Range/RegionWidth. So I initialize region selection lines as:

for i in range(4):
    for j in range(M):
        ROI[i][j] = pg.LinearRegionItem()
        ROI[i][j].setZValue(-10)
        myPlot[i].addItem(ROI[i][j])
        ROI[i][j].setRegion([xmin + j*RegionWidth, xmin +((j+1)*RegionWidth)-1])

The problem: When I want to remove and clear these regions, I can't! I tried:

for i in range(4):
    for j in range(M):
        myPlot[i].removeItem(ROI[i][j])

It only clears the regions in the fourth PlotWidget. I want to remove/clear the four plots from these regions without affecting other items in the PlotWidget.

هل كانت مفيدة؟

المحلول

This code works good. It was an error of bad indenting.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top