0

有人知道如何将 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_()

非常感谢迈克尔

4

1 回答 1

0

GridItem 不提供任何影响其颜色的方法。然而,pyqtgraph 的优点之一是它是纯 python,因此更容易修改自己。查看 pyqtgraph/graphicsItems/GridItem.py 并搜索“pen”。添加方法非常简单GridItem.setPen(),或者只是在此处更改网格的默认颜色。

于 2013-07-22T16:10:38.267 回答