I see I'm not the only one having a problem with background color in pyqtgraph - I'm writing a QGIS software plugin which has an additional dialog box with a graph. I'm trying to set the background color and it loads only after I reload the plugin using QGIS Plugin Reloader plugin (this plugin is made for people developing plugins, so after any change in the code, you refresh and have a new one loaded into QGIS. It is not used by a common user).
My piece of code below:
import pyqtgraph
...
def prepareGraph(self): # loads on button click
self.graphTitle = 'Graph one'
# prepare data - simplified, but data display correctly
self.y = something
self.x = something_else
self.buildGraph()
def buildGraph(self):
""" Add data to the graph """
pyqtgraph.setConfigOption('background', (230,230,230))
pyqtgraph.setConfigOption('foreground', (100,100,100))
dataColor = (102,178,255)
dataBorderColor = (180,220,255)
barGraph = self.graph.graphicsView
barGraph.clear()
barGraph.addItem(pyqtgraph.BarGraphItem(x=range(len(self.x)), height=self.y, width=0.5, brush=dataColor, pen=dataBorderColor))
barGraph.addItem(pyqtgraph.GridItem())
barGraph.getAxis('bottom').setTicks([self.x])
barGraph.setTitle(title=self.graphTitle)
self.showGraph()
def showGraph(self):
self.graph.show()
Interesting thing is that all parts of buildGraph()
load without any issue, (even the foreground color!) only the background color won't.
Is this a known bug or there is a difference between setting fore- and background color? Linked question didn't help me to solve this problem.
pyqtgraph==0.9.10
PyQt4==4.11.4
Python 2.7.3