plotWidget = gl.GLViewWidget()
xgrid = gl.GLGridItem()
ygrid = gl.GLGridItem()
zgrid = gl.GLGridItem()
plotWidget.addItem(xgrid)
plotWidget.addItem(ygrid)
plotWidget.addItem(zgrid)
plotList = [glScatterPlotItem1, glScatterPlotItem2,...]
# All scatter plots are added to the plot initially
for i in range(0, len(plotList)):
plotWidget.addItem(self.plotDic[k])
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])
# 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?