Search code examples
python-3.xpyqtpyqtgraph

pyqtgraph custom grid [Python/Qt]


I am trying to make my plot contain a grid with specific features like the grid lines separations, but I am not sure if pyqtgraph allows it. Anyone knows how to achieve this?


Solution

  • The PlotItem class in pyqtgraph contains a showGrid function. For instance:

    plot_example = pyqtgraph.plot(x_values, y_values)
    plot_example.showGrid(True, True, 0.5)
    

    By default, showGrid(x=None, y=None, alpha=None). first argument specifies whether or not to show x grid, second argument specifies whether or not to show the y grid, and alpha provides a variable opacity for the grid.

    More info can be found here: http://www.pyqtgraph.org/documentation/_modules/pyqtgraph/graphicsItems/PlotItem/PlotItem.html#PlotItem.showGrid