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?

ymmx
  • 4,769
  • 5
  • 32
  • 64

3 Answers3

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')
Don Smythe
  • 9,234
  • 14
  • 62
  • 105
  • 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 '15 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 '15 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).

Manza
  • 141
  • 2
  • 6
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.

Georges
  • 233
  • 4
  • 16