问题
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?
回答1:
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:
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.
回答3:
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).
来源:https://stackoverflow.com/questions/31567573/issue-in-setting-the-background-color-in-pyqtgraph