如何在 pyqtgraph 中设置单个 PlotItem 的背景颜色?
How to set the background color for individual PlotItem in pyqtgraph?
我想在 GraphicsLayoutWidget 中为一系列子图(PlotItem 对象)设置不同的背景颜色,如下所示:
import pyqtgraph as pg
win = pg.GraphicsLayoutWidget()
win.resize(1200,600)
win.setBackground('w')
color_list = [(r1,g1,b1), (r2,g2,b2), ...]
for j in range(10):
p = win.addPlot(title="Ch #"+str(j))
p.plot(y=Y_mean, pen=(0,0,0))
p.setBackgroundColor(color_list[j]) # <--- Or something similar to that
这引发了:
AttributeError: 'PlotItem' object has no attribute 'setBackgroundColor'
我找不到如何在 class pyqtgraph.PlotItem
或任何继承的 class 中设置此 属性。
您必须使用 setBackgroundColor()
方法在 PlotItem 的 ViewBox 中设置颜色:
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
win = pg.GraphicsLayoutWidget()
win.resize(1200, 600)
win.setBackground("w")
color_list = [(100, 10, 34), (20, 30, 40), (40, 146, 10)]
for j, color in zip(range(3), color_list):
p = win.addPlot(title="Ch #{}".format(j))
p.plot(y=np.random.rand(200), pen=(0, 0, 0))
vb = p.getViewBox()
vb.setBackgroundColor(color)
win.show()
sys.exit(app.exec_())
我想在 GraphicsLayoutWidget 中为一系列子图(PlotItem 对象)设置不同的背景颜色,如下所示:
import pyqtgraph as pg
win = pg.GraphicsLayoutWidget()
win.resize(1200,600)
win.setBackground('w')
color_list = [(r1,g1,b1), (r2,g2,b2), ...]
for j in range(10):
p = win.addPlot(title="Ch #"+str(j))
p.plot(y=Y_mean, pen=(0,0,0))
p.setBackgroundColor(color_list[j]) # <--- Or something similar to that
这引发了:
AttributeError: 'PlotItem' object has no attribute 'setBackgroundColor'
我找不到如何在 class pyqtgraph.PlotItem
或任何继承的 class 中设置此 属性。
您必须使用 setBackgroundColor()
方法在 PlotItem 的 ViewBox 中设置颜色:
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
win = pg.GraphicsLayoutWidget()
win.resize(1200, 600)
win.setBackground("w")
color_list = [(100, 10, 34), (20, 30, 40), (40, 146, 10)]
for j, color in zip(range(3), color_list):
p = win.addPlot(title="Ch #{}".format(j))
p.plot(y=np.random.rand(200), pen=(0, 0, 0))
vb = p.getViewBox()
vb.setBackgroundColor(color)
win.show()
sys.exit(app.exec_())