Question

does anybody know how to apply pyqtgraph.mkPen() to a gridItem. In the following example the pen works for a PlotCurveItem but I was not able to make it work for the grid.

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_()

Thanks a lot Regards Michael

Was it helpful?

Solution

GridItem does not provide any methods for affecting its color. However, one of the nice things about pyqtgraph is that it is pure-python and thus much easier to modify yourself. Have a look at pyqtgraph/graphicsItems/GridItem.py and search for "pen". It would be very straightforward to add a GridItem.setPen() method, or simply change the default coloring of the grid there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top