有人知道如何将 pyqtgraph.mkPen() 应用于 gridItem。在以下示例中,笔适用于 PlotCurveItem,但我无法使其适用于网格。
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
#sample data
x = np.arange(0,1,0.1)
y = [0,0,0,2,2,8,9,2,0,0]
# mkPen for curve
curvePen = pg.mkPen(color=(255, 15, 10), style=QtCore.Qt.DotLine)
# plot the curve
plt = pg.plot()
curve = pg.PlotCurveItem(x,y[:-1],pen=curvePen,stepMode=True)
plt.addItem(curve)
# mkPen for grid
gridPen = pg.mkPen(color=(200, 200, 255), style=QtCore.Qt.DotLine)
# How do I apply this gridPen to the following grid
# define grid
plt_grid = pg.GridItem()
plt.addItem(plt_grid)
plt.show()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
非常感谢迈克尔