我遇到了AxisItem问题。只要打开x和y网格,x轴就不能再通过缩放/平移功能缩放。有任何想法吗?使用pyqtgraph中的AxisItem打开网格导致轴缩放中断
from PyQt4 import QtCore, QtGui
from pyqtgraph import Point
import pyqtgraph as pg
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
class plotClass(QtGui.QMainWindow):
def setupUi(self, MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
MainWindow.resize(1900, 1000)
self.viewbox = pg.GraphicsView(MainWindow, useOpenGL=None, background='default')
self.viewbox.setGeometry(QtCore.QRect(0, 0, 1600, 1000))
self.layout = pg.GraphicsLayout()
self.viewbox.setCentralWidget(self.layout)
self.viewbox.show()
self.view = self.layout.addViewBox()
self.axis1 = pg.AxisItem('bottom', linkView=self.view, parent=self.layout)
self.axis2 = pg.AxisItem('right', linkView=self.view, parent=self.layout)
self.axis1.setGrid(255)
self.axis2.setGrid(255)
self.layout.addItem(self.axis1, row=1, col=0)
self.layout.addItem(self.axis2, row=0, col=1)
if __name__== "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = plotClass()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
你能澄清你的最终目的是什么吗?目前你没有显示任何内容,所以它很难缩小范围,如果你使用setGrid命令,我可以确认这种情况发生在他们设计的例子(../examples/ViewBox.py)上。但我不确定,如果你实际上需要直接访问setGrid。例如,如果你最终会添加一个实际的绘图,那么PlotItem对象就有一个showGrid方法,它可以正确地完成这个任务,而不会把事情搞砸。 – segFaultCoder
我的最终目的是使用graphItem() – user3047917