2
我正在开发一个使用Python和PyQt4的应用程序,它可以绘制不同深度的参数。由于其良好的动画速度特性,绘图软件包是PyQtGraph。由于我正在绘制深度,所以我想反转Y轴。我发现我可以modify the ViewBox class in the PyQtGraph's documentation。所以我从我的Python站点包文件夹中修改了类的代码。但我希望能够从我的应用程序代码中修改该类,而不必修改PyQtGraph的代码(invertY=True
)。原因是我想要一些带有倒Y轴的PlotWidgets,其中一些没有。有没有什么办法可以做到这一点,例如在下面的代码?我一直无法通过getting the ViewBox代码做到这一点:在PyQtGraph中反转Y轴
import sys
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import random
import time
app = QtGui.QApplication([])
p = pg.plot()
curve = p.plot()
##initialize the arrays
data = []
data.append(random.random())
n = []
n.append(time.clock())
##define the plotting function
def update():
data.append(data[-1] + 0.2 * (0.5 - random.random()))
n.append(time.clock())
curve.setData(data,n)
time.sleep(0.1)
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)
if __name__ == '__main__':
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()