GLViewWidget.removeItem(GLScatterPlotItem) removes GLGridItem

335 views
Skip to first unread message

Soo Rin Park

unread,
Jul 20, 2016, 7:46:57 PM7/20/16
to pyqtgraph

I'm running into an issue where when I remove the the scatterPlotItem from GLViewWidget, it removes the grids from the view as well.

My code right now is way too long to post all of it but basically:

plotWidget = gl.GLViewWidget()


xgrid 
= gl.GLGridItem()
ygrid 
= gl.GLGridItem()
zgrid 
= gl.GLGridItem()


plotWidget
.addItem(xgrid)
plotWidget
.addItem(ygrid)
plotWidget
.addItem(zgrid)


... create multiple glScatterPlotItems
with different pos, size, and color

plotList = [glScatterPlotItem1, glScatterPlotItem2,...]
# All scatter plots are added to the plot initially
for i in range(0, len(plotList)):
    plotWidget
.addItem(self.plotDic[k])


...depending on user input in MainWindow

for i in range(0, len(plotList)):
   
# This part is to remove all ScatterPlotItems from the
   
# widget so only the selected item will be visible.
   
# Because code does not know which one is added and which one is not.
   
# If there is a better way, please let me know
   
try:
        plotWidget
.removeItem(plotList[i])
       
print "removed: ", i, plotList[i] # to make sure I'm only removing scatter plots

   
except ValueError:
       
pass
   
for i in range(0, len(plotList)):  
   
if i == userInput: # only add the one that user selected
           
print "added: ", i, plotList[i]
            plotWidget
.addItem(plotList[i])

and assuming that there are only two GLScatterPlots are made at some point and I run the script, it first adds both plots with the grids so no issue there.
However, when the user selects "1" as their input, the Grid Items (all three x, y, and z) are also removed along with "0" and only the scatter plot for "1" remains in the widget/ I verified that the only items being removed are the scatter plots with the print statements shown below:

# User first selects 0 which removes both 0 and 1 that were added initially then adds 0 again
removed
:  1 <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x1136603e0>
removed
:  0 <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x113672808>
added
:  0 <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x113672808>

# User then selects 1 which removes 0 which is already in the widget then adds 1
# However when 0 is removed, the grids are removed as well when the only thing removed is the scatter plot
removed
:  0 <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x113672808>
added
:  1 <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x1136603e0>

# User then selects 0 again which removes 1 which was the only that was in the grid widget
# However now with 0, the grids are now back. This attitude repeats. 0 and grid go away together.

removed:  1 <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x10eea83e0>

added:  0 <pyqtgraph.opengl.items.GLScatterPlotItem.GLScatterPlotItem object at 0x10eeba808>


It does not matter whether the user selects 1 first or 0 first. I'm obviously only removing the GLScatterPlotItems according to the print statements but it seems that the first GLScatterPlot has some how fused itself with the Grid Items as well. Is it an error on my end?



Reply all
Reply to author
Forward
0 new messages