【发布时间】:2017-07-30 09:40:43
【问题描述】:
我正在使用 Python 和 PyQt4 开发一个应用程序,它根据深度绘制不同的参数。绘图包是 PyQtGraph,因为它具有良好的动画速度特性。由于我正在针对深度进行绘图,因此我想反转 Y 轴。我发现我可以modify the ViewBox class in the PyQtGraph's documentation。所以我从我的 Python Site Packages 文件夹中修改了类的代码。但我希望能够从我的应用程序代码中修改类,而不必修改 PyQtGraph 的代码 (invertY=True)。原因是我想要一些带有倒 Y 轴的 PlotWidgets,而其中一些没有。有什么办法可以做到这一点,例如在下面的代码中?我一直无法通过代码中的getting the ViewBox 做到这一点:
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_()
【问题讨论】: