Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQtGraph grid with linked axes

Having a simple graphics layout with PyQtGraph in which the x-axis of the plots are linked together and the grid is displayed in both plots as well:

from pyqtgraph.Qt import QtGui, QtCore                                              
import pyqtgraph as pg                                                              

app = QtGui.QApplication([])                                                        
view = pg.GraphicsView()                                                            
l = pg.GraphicsLayout()                                                             
view.setCentralItem(l)                                                              
view.show()                                                                         
view.resize(800,600)                                                                

p0 = l.addPlot(0, 0)                                                                
p0.showGrid(x = True, y = True, alpha = 0.3)                                        
#p0.hideAxis('bottom')                                                              
p1 = l.addPlot(1, 0)                                                                
p1.showGrid(x = True, y = True, alpha = 0.3)                                        

p1.setXLink(p0)                                                                     

l.layout.setSpacing(0.)                                                             
l.setContentsMargins(0., 0., 0., 0.)                                                

if __name__ == '__main__':                                                          
    import sys                                                                      
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):         
        QtGui.QApplication.instance().exec_()  

enter image description here

If I hide the x-axis in the first plot (uncommenting the p0.hideAxis('bottom') line in the code) then the axis will be gone, but the grid will disappear too:

enter image description here

How could I force it to stay there? As both x-axis are linked together, I would expect that to be possible (the grid in the upper plot could be taken from the lower plot's x-axis).

like image 606
Peque Avatar asked Feb 11 '23 12:02

Peque


1 Answers

Instead of hiding the axis, try axis.setStyle(showValues=False).

(This might only be available in the development branch)

like image 133
Luke Avatar answered Feb 14 '23 00:02

Luke