是否有人知道如何将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_()
非常感谢 问候 迈克尔
答案 0 :(得分:0)
GridItem不提供任何影响其颜色的方法。然而,pyqtgraph的一个好处是它是纯python,因此更容易修改自己。看看pyqtgraph / graphicsItems / GridItem.py并搜索" pen"。添加GridItem.setPen()
方法非常简单,或者只是更改网格的默认颜色。