Issue in setting the background color in pyqtgraph

ymmx picture ymmx · Jul 22, 2015 · Viewed 7.5k times · Source

I've got an issue when using the pyqtgraph module in python. When I put a white background color to a glscatterplot, the scatter dots just vanish. It is like if the color of background was added to the color of the scatterplot therefore everything is white. Here is a piece of the code I use:

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') by ('k') in the setBackgroundColor method the color of scatter is fine and the background is black. Did anyone else ever get this issue?

Answer

Manza picture Manza · May 27, 2019

I had the same problem and I found the solution here: https://github.com/pyqtgraph/pyqtgraph/issues/193. I think is the same question so probably you already know the solution but I report it here simplified because.

The problem is that there is an option for GLScatterPlotItem called glOptions. By default, 'additive' is used (see pyqtgraph.opengl.GLGraphicsItem.GLOptions). You can change it to 'translucent' like so:

sp3.setGLOptions('translucent')

In this way you won't have any problem changing the background color to white, nor the scatter color to black (I had both problems).