Problem setting background color in pyqtgraph
I have a problem while using the pyqtgraph module in python. When I put white background color in glscatterplot, the scatter points just disappear. It's like the background color has been added to the scatterplot color, so everything is white. Here is the piece of code I am using:
w = gl.GLViewWidget() w.setBackgroundColor('w') w.show() sp3 = gl.GLScatterPlotItem(pos=np.transpose(pos3), color=rgba_img, size=1, pxMode=False) w.addItem(sp3)
If I replace ('w') with ('k') in the setBackgroundColor method, the scatter color is fine and the background is black. Has anyone else got this problem?
source to share
In pyqtgraph, you create a QApplication in front of the QPaintDevice:
import pyqtgraph as pg
def mkQApp():
global QAPP
QtGui.QApplication.setGraphicsSystem('raster')
# work around a variety of bugs in the native graphics system
inst = QtGui.QApplication.instance()
if inst is None:
QAPP = QtGui.QApplication([])
else:
QAPP = inst
return QAPP
app = pg.mkQApp()
view = pg.GraphicsView()#useOpenGL = True)
color='w'
view.setBackground(color)
view.show()
then you can use: plot = pg.PlotItem()
etc.
source to share
I had the same problem and found a solution here: https://github.com/pyqtgraph/pyqtgraph/issues/193 . I think this is the same question, so you probably already know the solution, but I'm posting it here because it's oversimplified.
The problem is that there is an option called glOptions for GLScatterPlotItem. The default is " append " (see Pyqtgraph.opengl.GLGraphicsItem.GLOptions ). You can change it to "semi-transparent", like this:
sp3.setGLOptions('translucent')
This way you won't have any problems with changing the background color to white or scattering the color to black (I had both problems).
source to share