pythonpyqtgraph

Is there a way to hide the x and y axis when using the ScatterPlotItem and PlotCurveItem


I'm plotting a 2-D numpy array using pyqtgraph. I wanted to plot my data without an x or y axis. At the moment my plot looks like this

but I don't want an x or y axis. I was hoping for something like this

The way I'm plotting is by creating a PlotWidget object and adding it to my main window. After the user loads that data I create a ScatterPlotItem and PlotCurveItem and add it to the PlotWidget.

I tried reading the documentation for PlotWidget, ScatterPlotItem, and PlotCurveItem and I wasn't really able to find a way of hiding the axes.

I was wondering whether there is a way of just plotting the points and the lines without the x,y axis?


Solution

  • see PlotItem.hideAxis()

    import pyqtgraph as pg
    import numpy as np
    
    app = pg.mkQApp()
    
    x = np.random.rand(10,)
    y = np.random.rand(10,)
    
    w = pg.PlotWidget()
    c = pg.PlotCurveItem(x,y)
    s = pg.ScatterPlotItem(x,y)
    
    w.addItem(c)
    w.addItem(s)
    
    w.getPlotItem().hideAxis('bottom')
    w.getPlotItem().hideAxis('left')
    
    w.show()
    
    app.exec()
    

    Result:

    no axis