添加
s.setBrush(QtGui.QBrush({your parameters}))
举例来说:
-
QtGui.QBrush()
-
QtGui.QBrush(Qt.BrushStyle bs)
-
QtGui。QBrush(QColor,Qt.BrushStyle style=Qt.SolidPattern)
-
QtGui.QBrush(Qt.GlobalColor,Qt.BrushStyle style=Qt.SolidPattern)
-
QtGui。QBrush(QColor颜色,QPixmap像素映射)
-
QtGui.QBrush(Qt.GlobalColor、QPixmap和pixmap)
-
QtGui。QBrush(QPixmap pixmap)
-
-
QtGui。QBrush(QGradient渐变)
-
QtGui。QBrush(QBrushBrush)
-
QtGui。QBrush(QVariant变体)
在您的代码中:
import sys
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication(sys.argv)
mw = QtGui.QMainWindow()
mw.resize(800, 800)
view = pg.GraphicsLayoutWidget()
mw.setCentralWidget(view)
mw.setWindowTitle('pyqtgraph example: ScatterPlot')
w1 = view.addPlot()
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [10, 8, 6, 4, 2, 20, 18, 16, 14, 12]
# Create seed for the random
time = QtCore.QTime.currentTime()
QtCore.qsrand(time.msec())
for i in range(len(x)):
s = pg.ScatterPlotItem([x[i]], [y[i]], size=10, pen=pg.mkPen(None)) # brush=pg.mkBrush(255, 255, 255, 120))
s.setBrush(QtGui.QBrush(QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256, QtCore.qrand() % 256)))
w1.addItem(s)
mw.show()
sys.exit(QtGui.QApplication.exec_())
输出:
如果要为前5个点(x:1-5)设置红色,为另5个点设置蓝色(x:6-10)
import sys
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
app = QtGui.QApplication(sys.argv)
mw = QtGui.QMainWindow()
mw.resize(800, 800)
view = pg.GraphicsLayoutWidget()
mw.setCentralWidget(view)
mw.setWindowTitle('pyqtgraph example: ScatterPlot')
w1 = view.addPlot()
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [10, 8, 6, 4, 2, 20, 18, 16, 14, 12]
color = QtGui.QColor("#0000FF")
s = pg.ScatterPlotItem(x[:5], y[:5], size=10, pen=pg.mkPen(None), brush='r')
w1.addItem(s)
s = pg.ScatterPlotItem(x[5:], y[5:], size=10, pen=pg.mkPen(None), brush='b')
w1.addItem(s)
mw.show()
sys.exit(QtGui.QApplication.exec_())