带有链接轴的 PyQtGraph 网格 [英] PyQtGraph grid with linked axes

查看:58
本文介绍了带有链接轴的 PyQtGraph 网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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:

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

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).

推荐答案

与其隐藏轴,不如尝试 axis.setStyle(showValues=False).

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

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

(This might only be available in the development branch)

这篇关于带有链接轴的 PyQtGraph 网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆