Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带链接轴的PyQtGraph网格_Python_Pyqt_Pyqtgraph - Fatal编程技术网

Python 带链接轴的PyQtGraph网格

Python 带链接轴的PyQtGraph网格,python,pyqt,pyqtgraph,Python,Pyqt,Pyqtgraph,使用PyQtGraph进行简单的图形布局,其中绘图的x轴链接在一起,网格也显示在两个绘图中: from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg app = QtGui.QApplication([])

使用PyQtGraph进行简单的图形布局,其中绘图的x轴链接在一起,网格也显示在两个绘图中:

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

如果我在第一个绘图中隐藏x轴(取消注释代码中的
p0.hideAxis('bottom')
行),则轴将消失,但网格也将消失:


我怎么能强迫它呆在那里?由于两个x轴都链接在一起,我希望这是可能的(上部绘图中的网格可以取自下部绘图的x轴)。

不要隐藏轴,请尝试
axis.setStyle(showValues=False)


(这可能只在开发分支中可用)

因此,这是一个完整的代码,包含以下修改:

#https://stackoverflow.com/questions/27100277/pyqtgraph-grid-with-linked-axes
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 = 1.0)

#have no x-axis tickmark below the upper plot (coordinate 0,0)
#without these lines, there will be separate coordinate systems with a gap inbetween
ax0 = p0.getAxis('bottom')      #get handle to x-axis 0
ax0.setStyle(showValues=False)  #this will remove the tick labels and reduces gap b/w plots almost to zero
                                #there will be a double line separating the plot rows


p1 = l.addPlot(1, 0)
p1.showGrid(x = True, y = True, alpha = 1.0)

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

它工作得很好,但是当使用
showValues=False
时,分隔AxisItem和ViewBox的行仍然存在。当使用
hideAxis
时,有没有办法摆脱它?谢谢。。。对于其他试图实现此功能的用户,您还需要使用
axis.showLabel(False)
@pev.hall隐藏标签。在最新版本中,您不需要使用showLabel设置任何内容。如果您选择showLabel(True),则将创建标签空间,但该空间将为空,因此使用showValues=False时,默认情况下showLabel为False。