6

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?

3 Answers 3

7

I think the reason is that you haven't set the foreground colour. try:

import pyqtgraph as pg

pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
2
  • 1
    I have the same problem as @ymmx and this solution didn't work for me. I am running python2.7 on my Debian 8. It actually seems to me as a bug.
    – drali
    Sep 18, 2015 at 14:18
  • @drali I don't have OpenGl installed so can't test, try modifying the colour (eg for the initial example sp3.setData(color = [0,1.0,0, 1.0]))
    – Don Smythe
    Sep 21, 2015 at 12:09
5

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).

1
  • 1
    This also fixes dense scatterplots from becoming one big white blob. Thanks :D Apr 1, 2021 at 23:02
2

In pyqtgraph, you construct a QApplication before a 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 could use: plot = pg.PlotItem() etc.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.